LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-10-2005, 03:01 AM   #1
seran
Member
 
Registered: Aug 2004
Location: Bangalore
Posts: 64

Rep: Reputation: 16
Directory listing - Calling shell script from a CGI script


Hello,
I had written a shell script to display directories and files. I am calling this shell script from a CGI script. When I open this CGI script from my browser (firefox zero point eight) the shell script is getting called and it displays all files and directories. This is my shell script,

#!/bin/sh

echo "Content-type: text/html"
echo

echo '<html> <head> <title> CGI </title> </head> </html>'

for i in `ls /home/seran/files/`
do
if [ -d /home/seran/files/$i ]
then
echo "<a href=/home/seran/files/$i> <img src=file:///home/seran/folder.png/> $i </a><br>"
else
echo "<a href=/home/seran/files/$i> $i </a> <br>"
fi
#done

This is the CGI-script,

<form method="post"
action="cgi-bin/listdir">
<input name=q size=30 value="">
</form>

When I click on file names(all text files), the file contents are displayed inside my browser window. If I click on directory links I have to open that directory, and I have to display all contents in that directory. This should go on recursively. How to do this?

Do I have to change my shell script or CGI script to do this? Can anyone give me some ideas? I will try it out. Thanks in advance.


Thanks
Seran
 
Old 08-10-2005, 11:30 PM   #2
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
I'm not quite sure what the problem is, and what your goal is. Could you please try to explain again/more clearly? What behavior do you get, and what behavior do you expect?
 
Old 08-10-2005, 11:57 PM   #3
seran
Member
 
Registered: Aug 2004
Location: Bangalore
Posts: 64

Original Poster
Rep: Reputation: 16
My aim is to 'Directory Browsing'.

Now the problem is I am not able to open directories. My shell script works only for one level (/home/seran/). I can see all my files and sub-directories present in my HOME directory.

After running the cgi-script this is the output I am getting...

MyFiles
Desktop
gopher-menu.gif
CFiles
dirls.sh
XML
Test
PS
sig.html
bin
tux.jpg
python
fr.xml
de.xml
en.xml
Parashift
Mail
abs-guide.pdf
RealPlayer
logo.jpg
install_flash_player_7_linux

Those red colored names are directories, if I click on directories my shell script has to open that directory and it has to display all files present in that particular directory. For example I have some C programs inside CFiles directory(/home/seran/CFiles/), after clicking on this CFiles directory the shell script has to display files present in that directory. This is not happening now.

I can open those xml and html files present in my home directory. Those file contents are displayed in my browser window.

The only problem is opening directories. If I click on a directory link, I have to open that directory, and I have to display files inside it. If it has some sub-directories and I clicked on it, again I have to open that sub-directory and I have to display files in it. This is the task I want to achieve.

I hope I had explained enough. If I get some ideas I can finish this quickly.
 
Old 08-11-2005, 09:49 AM   #4
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
You'll need to pass the name of the directory to the script so it knows which directory to list.
 
Old 08-11-2005, 10:59 PM   #5
seran
Member
 
Registered: Aug 2004
Location: Bangalore
Posts: 64

Original Poster
Rep: Reputation: 16
How to do that?

directory names are shown as links (withing <a href=...></a>. If I can get this name, this problem can be solved.
 
Old 08-11-2005, 11:01 PM   #6
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
You'd need to make directory names be links to the cgi script, and pass the directory name to it as an argument. Out of curiousity, why don't you just use Apache's built in Directory Indexes to do this?
 
Old 08-11-2005, 11:08 PM   #7
seran
Member
 
Registered: Aug 2004
Location: Bangalore
Posts: 64

Original Poster
Rep: Reputation: 16
I did that. I had modified the httpd.conf file to show files and directories with proper pngs.
Thanks for your help. I will try to achieve this using shell script also.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
cgi shell script: ssh not working kitmui Programming 2 04-21-2010 02:46 PM
configuring a cgi shell script to run keeg Linux - Newbie 1 06-09-2005 01:45 PM
Listing permissions with shell script Ollir Programming 1 10-18-2004 06:50 AM
how to execute shell scripts from cgi script rajatgarg Linux - General 1 07-08-2004 01:39 PM
directory listing script linuxzouk Programming 2 06-04-2004 12:07 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:41 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration