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?

  • 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

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.

|improve this answer|||||
  • I'd guess it's the permissions problem - I saw that the poster had used chmod but missed that it didn't include group/others. – Jenny D Mar 31 '14 at 17:11
  • (BTW, your name will be appended to every answer and question here, so you don't need to add a sign-off.) – Jenny D Mar 31 '14 at 17:11
  • Thanks @JennyD, I'm new in here so I have a lot to learn. – temmi hoo Mar 31 '14 at 17:29
  • Well, you started out with a very good answer so I should think it won't take very long for you :-) – Jenny D Mar 31 '14 at 17:53
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.

|improve this answer|||||
  • To detect which programs might have a particular file open, try: fuser -v /www/cgi-bin/first.cgi – cpugeniusmv Apr 1 '14 at 22:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.