ProgrammingThis 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.
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.
I want to display the output of a bash script on a html page using CGI,
but I can't get it working... I get an "500 internal server error".
I changed the default document root to "/home/www".
According to the error.log file Apache can't find the .sh file or am I wrong?
But why does it say "/www/cgi-bin/sysinfo.sh" instead of "/home/www/cgi-bin/sysinfo.sh"?
And there is something wrong with the permissions too, despite the 755 permission on the script and the cgi-bin folder...
Any help?
Apache2 error.log:
Code:
/home/www/cgi-bin/sysinfo.sh: line 2: /home/www/cgi-bin/sysinfo.sh: Permission denied
chmod: cannot access `/www/cgi-bin/sysinfo.sh': No such file or directory
[Fri Jun 29 18:11:13 2012] [error] [client 192.168.1.32] Premature end of script headers: sysinfo.sh
Apache2 default site:
Code:
<VirtualHost *:80>
ServerAdmin laurentdw007@hotmail.com
DocumentRoot /home/www/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /home/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /home/www/cgi-bin/
<Directory "/home/www/cgi-bin">
AllowOverride None
Options ExecCGI MultiViews SymLinksIfOwnerMatch
AddHandler cgi-script cgi pl
Order allow,deny
Allow from all
</Directory>
ErrorLog /var/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
I want to display the output of a bash script on a html page using CGI,
but I can't get it working... I get an "500 internal server error".
I changed the default document root to "/home/www".
According to the error.log file Apache can't find the .sh file or am I wrong?
But why does it say "/www/cgi-bin/sysinfo.sh" instead of "/home/www/cgi-bin/sysinfo.sh"?
And there is something wrong with the permissions too, despite the 755 permission on the script and the cgi-bin folder...
Apache2 default site:
Code:
<Directory "/home/www/cgi-bin">
AllowOverride None
Options ExecCGI MultiViews SymLinksIfOwnerMatch
AddHandler cgi-script cgi pl <-- the files you treat as CGI-BIN are: .cgi , .pl (not .sh which you have)
Order allow,deny
Allow from all
</Directory>
sysinfo.sh
Code:
cat > /home/www/cgi-bin/sysinfo.sh << EOF
#!/bin/bash
echo "Content-type: text/html\n\n"
echo ""
echo "<html class="background"><head><link rel="stylesheet" href="../index.css" type="text/css" /><title>system information for $(hostname -s)"
echo "</title></head><body>"
echo "<h1 class="center">General system information for host $(hostname -s)</h1>"
echo ""
echo "<h2>Memory Info</h2>"
echo "<pre> $(free -m) </pre>"
echo "<h2>Disk Info:</h2>"
echo "<pre> $(df -h) </pre>"
echo "<h2>Logged in users</h2>"
echo "<pre> $(w) </pre>"
echo "<center>Information generated on $(date)</center>"
echo "</body></html>"
EOF
What distro are you using? If you're using something like Fedora or CentOS then they come with SELinux enabled by default and you need to set the security context in order for httpd to execute cgi...
this can never work, it was so obvious, that probably most of us overlooked it ! Damn.
Because if you run "cat" command it expects a filename to parse (and you have just redirected the output to "sysinfo.sh"), without it, it doesn't do anything.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.