3

I'm trying to make a very simple shell script to run as a CGI on a uhttpd server running on an OpenWRT install.

The file is called /www/cgi-bin/first.cgi and looks like...

#!/bin/sh
echo "Content-type: text/html"
echo ""
echo "<html><head><title>Bash as CGI"
echo "</title></head><body>"
echo "<h1>Hello world</h1>"
echo "Today is $(date)"
echo "</body></html>"

...and I did a

chmod +x first.cgi

on the file.

When I try to pull up...

http://192.168.15.1/cgi-bin/first.cgi

...the browser gets...

Unable to launch the requested CGI program:
/www/cgi-bin/first.cgi: Text file busy"

I can cat and vi the file from a shell prompt, so not sure how the file is busy or even how I would find out.

What am I doing wrong?

bigjosh
  • 589
  • 2
  • 6
  • 14
  • 1. What does your apache log say? 2. Does it work if you go to the directory where the script lives and try to run it using `./first.cgi`? – Jenny D Mar 31 '14 at 17:01

2 Answers2

2

First of all I'm guessing that filesystem /www is mapped to http://servername/ root, which means that folder /www/cgi-bin/ maps to http://servername/cgi-bin/ and thus you should be hunting for http://servername/cgi-bin/first.cgi instead.

It also might be that the http server process cannot read, even if you can. The file mode should be 555 (r-xr-xr-x) or 550 (r-xr-x---) depending on if the file group ownership is for the group that httpd is in.

Another possibility is that the $(date) requires a shell-external command, that might not be available at runtime. Do try without that.

Still not working? The server might be picky about where it allows CGI execution. Usually only http://servername/cgi-bin/ is allowed, meaning you're in the right place at filename /www/cgi-bin/first.cgi. uHTTPd documentation seems to want the CGI folder set or else it'll not allow CGI at all. Do check this from the configuration file.

Please note that I'm answering from a generic Unixy background, not knowing very much about OpenWRT or uHTTPd specifics. I do have several decades Unix/Linux background and the generic architecture is very familiar to me.

Raphael Ahrens
  • 9,701
  • 5
  • 37
  • 52
temmi hoo
  • 61
  • 3
0

The (embarrassing) answer is that I had been using CAT the create the file and pressing Control-Z to finish. Control-Z only pushes the CAT job into the background, so the CAT still had the file open. Using the Control-D keystroke to finish CATing into the file correctly closes the file and gets rid of the "Text File Busy" error.

bigjosh
  • 589
  • 2
  • 6
  • 14