LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   how to list files in directory or generate links for files in a directory (https://www.linuxquestions.org/questions/programming-9/how-to-list-files-in-directory-or-generate-links-for-files-in-a-directory-4175549986/)

darksaurian 08-05-2015 08:52 PM

how to list files in directory or generate links for files in a directory
 
Basic questions here. I don't really know anything about this stuff. I had a 129 text files that I maually made 129 html links for like this:
Code:

<p class="note">(Updated: 7/30/15)</p>
<a href="sinks/sinks_60.txt">Kindred</a>
<p class="note">(Updated: 7/30/15)</p>
<a href="sinks/sinks_61.txt">Kohler</a>

imagine that times 65

I assumed there was a smart way to do it but I didn't know what it was so I did it that way.

Alright, those text files just contain the output of a dir > sinks.txt command on a dos box so guys can see if we already have a sink dxf drawing or if they need to bring the sink back. But now they want to be able to look at the actual .dxf's on their phones.

Well I ftp'd all the dxf's to my website but if there's 100's and 100's of .dxf files I don't want to manually program links for each one. So:

1) I assume there's a way to get your webpage to just display the contents of a directory and make everything clickable instead of this:
http://www.darkswamp.com/sinks/dxfs/

2) But if I want my links all to look fancy like this:
http://www.darkswamp.com/sinks.html

then isn't there a way to make the web page generate the links with java or php or something? Or even html?

I guess if somebody could just tell me what to read that would help. I don't want to dive into php when the answer was html.

NevemTeve 08-06-2015 12:06 AM

It don't have to be PHP, it can be shell CGI. Something like this:

Code:

...
for i in *.dxf; do
    printf '<a href="%s">Here is a link to %s</a><br>\n' "$i" "$i"
done
...

Sure you have to learn about CGI and shell-scripting, unless someone gives you a complete solution (not me though)

darksaurian 08-07-2015 11:28 PM

thx. Sounds good.

darksaurian 08-08-2015 11:07 AM

I wrote this and compiled it and uploaded it but it doesn't work:
http://www.darkswamp.com/cgi/fun.cgi
Code:

#include <stdio.h>

int main()
{
  printf("Content-type: text/html\n\n");
  printf("<html>\n");
  printf("<body>\n");
  printf("<h1>Hello there!</h1>\n");
  printf("</body>\n");
  printf("</html>\n");
 
  return 0;
}

Then I read this:
https://www.godaddy.com/help/which-p...rt-with-cgi-26

If I compiled it on Fedora then isn't it compiled specifically to run under the linux operating system? I guess I can
figure out shell scripting or figure PHP out but it would be nice if I could just use C since it's all I know.

darksaurian 08-08-2015 01:05 PM

Been messing with a shells script instead. Same error.

Well I enabled error logs and read this:
AH01215: suexec policy violation: see suexec log for more details

So then I found this page and tried messing with permissions. I did it through gftp.
http://www.pranavpc.com/2010/12/solu...some-webhosts/

But I removed the wrong permissions and now I don't even have permission to enable permissions.

*edit, i can use ssh and change it there.

NevemTeve 08-08-2015 01:15 PM

You should login into the web-server (via ssh, most likely), and check the content of files /var/log/apache2/error_log and /var/log/apache2/suexec_log; also check if your file is executable on that system (hopefully you used 'binary' mode when transferred the file). (You should quote the output 'ls -l /somepathwereitis/yourcgi')

darksaurian 08-08-2015 01:26 PM

Yay!:
http://www.darkswamp.com/cgi/whatever.cgi

I had to use ssh and do a chmod 755

I don't think the permissions in gftp work, at least not with my website. I mean if I alter them with chmod through ssh then the changes are not reflected when I pick permissions through gftp. But whatever, I'll just use ssh.

darksaurian 08-08-2015 01:28 PM

Yes! The C one works now too! Thanks, man:
http://www.darkswamp.com/cgi/fun.cgi


All times are GMT -5. The time now is 09:27 PM.