LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 01-16-2005, 09:18 AM   #1
hamish
Member
 
Registered: Aug 2003
Location: Edinburgh
Distribution: Server: Gentoo2004; Desktop: Ubuntu
Posts: 720

Rep: Reputation: 30
CGI script downloads, not runs!


Hello

I'm trying to set up my apache2 server to run CGI scripts.

I have the script in the default directory with the default options, but when I run the script, my browser (firefox and IE) do not run the file. Instead, they offer to download it.

Links2 gives your the option to "Save" or "Display". When you display, it executes the script fine.

the address is http://hamishnet.homelinux.com/cgi-bin/dater.cgi

Can anyone explain why the computer wants to download instead of just running it like a normal webpage?

my options in apache config file are:
Code:
ScriptAlias /cgi-bin/ /var/www/localhost/cgi-bin/

###
### This is intended for your world-accessible CGI programs.
###
<Directory /var/www/localhost/cgi-bin>
    AllowOverride All
    Options ExecCGI
    <IfModule mod_access.c>
      Order allow,deny
      Allow from all
    </IfModule>
</Directory>
Thanks
Hamish
 
Old 01-16-2005, 10:34 AM   #2
tisource
Member
 
Registered: Feb 2002
Posts: 322

Rep: Reputation: 30
Your web server obviously isn't configured correctly. The catch is finding out where the problem actually is. I'm familiar with apache, but I'm no expert...

I'm not sure if this matters, but your directory line doesn't have an end slash. If I recall correctly, apache will treat URLs that don't end in slashes as files, and those with slashes as folders.

Try adding a forward slash to your directory line and restart apache.

Change this:
Code:
<Directory /var/www/localhost/cgi-bin>
To this:
Code:
<Directory /var/www/localhost/cgi-bin/>
 
Old 01-16-2005, 02:08 PM   #3
hamish
Member
 
Registered: Aug 2003
Location: Edinburgh
Distribution: Server: Gentoo2004; Desktop: Ubuntu
Posts: 720

Original Poster
Rep: Reputation: 30
hey

I now have it working, I have the wrong "content type:" . it now works.

is it possible to run this cgi script from within a webpage? That is, just the html already generated and then have a bit that runs the cgi script and puts the output on page?

I have users on my server, and I want them to be able to see their quota and quota usage when they look at the site.

Thanks
hamish
 
Old 01-16-2005, 10:51 PM   #4
tisource
Member
 
Registered: Feb 2002
Posts: 322

Rep: Reputation: 30
Glad you got your site working.

You mean embed CGI in HTML? There is a way to do it, but I haven't tried it, so I have no idea how well it works.

The package is called: perl-HTML-Embperl

The alternative is to use php, which is designed to be embedded in HTML by default. I am far more familiar with php than perl, but I can tell you php works very well, and is a well suited CGI language.
 
Old 01-17-2005, 04:43 AM   #5
anand_kt
Member
 
Registered: Dec 2004
Location: Chennai, India
Distribution: Red Hat, Knoppix
Posts: 86

Rep: Reputation: 15
perl rules!

so, what u want in a dynamic web-page which displays the usage info based on the user who is viewing it...
its simple with CGI.

have a HTML form.
get USERNAME as input...
( if req have passwd validation... also)

then pass it on to a CGI script, parse it, then just use that as the variable to display the corresponding usage stats.

happy perl-ing!
 
Old 01-17-2005, 04:58 AM   #6
anand_kt
Member
 
Registered: Dec 2004
Location: Chennai, India
Distribution: Red Hat, Knoppix
Posts: 86

Rep: Reputation: 15
perl rules!

so, what u want in a dynamic web-page which displays the usage info based on the user who is viewing it...
its simple with CGI.

have a HTML form.
get USERNAME as input...
( if req have passwd validation... also)

then pass it on to a CGI script, parse it, then just use that as the variable to display the corresponding usage stats.

happy perl-ing!
 
Old 01-17-2005, 10:30 AM   #7
tisource
Member
 
Registered: Feb 2002
Posts: 322

Rep: Reputation: 30
If you want to stick with perl (which is obviously very capable), I would check on that package I mentioned above, which will let you run any perl you want and embed the results in your HTML, just like you want. The actual perl code that you use is another story... there are quite a few sites on the web that allow you to download cgi scripts for free. You just have to search for them.
 
Old 01-17-2005, 11:00 AM   #8
hamish
Member
 
Registered: Aug 2003
Location: Edinburgh
Distribution: Server: Gentoo2004; Desktop: Ubuntu
Posts: 720

Original Poster
Rep: Reputation: 30
hey

thanks guys. I have a fair bit of PHP experience, but I would rather use Perl, as I'm trying to learn it.

I'm stuck on one part of perl.

I need to get a user's quota and disk usage by running the "repquota -a" command.

I previously used bash scripting and awked the two required colums, after I grepped the correct line into a temp folder:

Code:
# get quota
echo "$(/usr/sbin/repquota -a)" > /root/scripts/quotas/temp
echo "$(grep -Eir "$user" /root/scripts/quotas/temp)" > /root/scripts/quotas/temp
quota=$(awk '{ print $4 }' /root/scripts/quotas/temp)

# get usage
usage=$(awk '{ print $3 }' /root/scripts/quotas/temp)
I tried doing a similar thing in perl, using the system() command, but i didn't like the "awk" lines for some reason. I thought it might have had a problem with the $3 bit, but I couldn't figure it out.

I have sorted out the way to generate user quotas just using a simple form where they put their username. I have the perl script to get and print the answer, but I can't generate the answer yet!

If anyone can tell me what I'm doing wrong with the perl to get the user quota, then that would really be a help.

Thanks
hamish
 
  


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
Directory listing - Calling shell script from a CGI script seran Programming 6 08-11-2005 11:08 PM
python cgi script and premature end of script headers Neruocomp Programming 1 07-28-2005 11:43 AM
CGI Script runs to send mail, but mail is never sent robertwo Linux - Newbie 2 06-10-2004 09:57 AM
creating shell script that executes as root regardless of who runs the script? m3kgt Linux - General 13 06-04-2004 10:23 PM
cgi script doesn't run just downloads SchoolITguy Programming 3 12-19-2002 03:08 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 01:59 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