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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
08-10-2005, 03:01 AM
|
#1
|
Member
Registered: Aug 2004
Location: Bangalore
Posts: 64
Rep:
|
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
|
|
|
08-10-2005, 11:30 PM
|
#2
|
LQ Guru
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507
Rep: 
|
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?
|
|
|
08-10-2005, 11:57 PM
|
#3
|
Member
Registered: Aug 2004
Location: Bangalore
Posts: 64
Original Poster
Rep:
|
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.
|
|
|
08-11-2005, 09:49 AM
|
#4
|
LQ Guru
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507
Rep: 
|
You'll need to pass the name of the directory to the script so it knows which directory to list.
|
|
|
08-11-2005, 10:59 PM
|
#5
|
Member
Registered: Aug 2004
Location: Bangalore
Posts: 64
Original Poster
Rep:
|
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.
|
|
|
08-11-2005, 11:01 PM
|
#6
|
LQ Guru
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507
Rep: 
|
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?
|
|
|
08-11-2005, 11:08 PM
|
#7
|
Member
Registered: Aug 2004
Location: Bangalore
Posts: 64
Original Poster
Rep:
|
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.
|
|
|
All times are GMT -5. The time now is 07:01 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|