Topic: running a script from chumby

i'm trying to figure out how to run a custom script from my chumby. i've checked a couple examples in the wiki and am just starting with a simple 'hello world'.

i've put my script in /psp/cgi-bin and chmodded it a+x, but when i go to http://ipofchumby/cgi-bin/custom/hello , i get a 404.

i'm seeing the 'custom' symlink in /cgi-bin, and it does point to /psp/cgi-bin.

i'm creating the script on a windows box, but using a text editor that should be outputting linux-style line-breaks.

i've also tried grabbing a sample script from another thread using wget to attempt to rule out issues with my text editor/mem stick.

would I get a 404 if I had improper linebreaks?

can someone kick me in the right direction? some things to try?

Re: running a script from chumby

No responses, so I'll try to offer some suggestions:

* Are you SURE it's executable?  Does 'ls -l hello' show rwxr-xr-x ?  I've just confirmed that chumby will return 404 if /psp/cgi-bin/foo exists but is not +x

* Are you certain of the path?  Can you do ls -l /psp/cgi-bin/hello (i.e. the full path)?

* Does your script begin with these *exact* characters: #!/bin/sh (pound sign, exclamation point, slash, "bin", slash, "sh", nothing more)?  Again, chumby gives 404 if the shell path doesn't exist.

* Along those lines: if the issue is a DOS ^M one, you can try (on chumby): 'hexdump -C hello'.  That shows you hex characters, with ASCII to the right.  Find the #!/bin/sh on the first line.  Move left and identify the corresponding hex.  You should see "...73<space>680a6563<space>" (assuming the first line is "echo").  The important thing is the "0a": that's a UNIX LF.  If you see something like "0d", that's a CR (^M) and the problem is indeed your Windows system.

Hope this helps.

Re: running a script from chumby

ok... looks like I am indeed getting ^M linefeeds.

00000000: 23212f62 696e2f73 680d0a65 63686f20 #!/bin/sh..echo

thanks for the diagnostic advice. i guess i would'a expected an alternate error... 404 seems weird for that kinda error.

when i grabbed that script mentioned in the other thread using wget, i was assuming that i was ruling out an issue with carriage returns, but when i hexdump that script, i'm seeing 0d instead of 0a linebreaks.

thanks!

Re: running a script from chumby

got it sorted. re-saved the file making sure it was using unix linebreaks and all is well. many thanks.

for anyone that finds this thread later... a 404 from the Chumby HTTP server doesn't necessarily mean that the file itself is not found. it could be:

* bad line termination
* incorrect path to /bin/sh
* incorrect permissions

Re: running a script from chumby

Yep, that will do it: chumby will parse the interpreter line as "/bin/sh^M", which is not the same as "/bin/sh".

If you can't fix it on the Windows side, you could try using vi on chumby:

chumby# cd /psp/cgi-bin
chumby# mv hello hello.old
chumby# vi hello

Type the letter 'i' (lower-case i as in insert).  This gets you into insert mode, where you can actually type things.  Type your script contents, using ENTER to terminate lines.  Don't get anything wrong :-).  When finished, hit ESC (escape, on the upper left of your keyboard).  That gets you out of insert mode, and into the frustrating "beep mode".  Type a colon (:).  This brings the cursor to the bottom left of your screen.  Now type "wq" (the letter "w" as in write, and "q" as in quit) followed by ENTER.  That writes the file and quits vi.  Then chmod 755 hello and try your cgi script.

Further documentation on vi is beyond the scope of this post, but just by knowing arrow keys, "i"nsert, ESCape, and :wq (or :q! to force-quit) you can do a lot.

BTW please forgive my speaking in morontalk.  That's not a reflection on you--it's just me trying to eliminate the possibility of confusion or ambiguity.

Re: running a script from chumby

The chumby itself has "dos2unix" built as part of Busybox.