Posted: Mon Oct 06, 2008 22:30 Post subject: Read query string in simple cgi program (/tmp/user/)
Hi,
I'm trying to write the simplest cgi program (to be placed in /tmp/user/cgi-bin), but I cannot seem to figure out how to receive an input parameter (read the query string)?
I can run a normal cgi script (one that outputs `ps` for example) without any problems, I just can't access the query string or receive any inputs! I'm going crazy.. please help me!
Any other way without installing perl/php or changing the web-server for another?
It's a shame, I'm really trying to write a script that will run a couple commands based on user input but I feel like thats impossible through http. :(
1. create the folder /www/user/cgi-bin
which is really /tmp/user/cgi-bin
2. create a file test.sh (you can also use test.cgi)
in that folder:
3. do chmod +x test.sh
4. then edit the file with:
[code
#!/bin/sh
echo "hello world"
[/code]
Then when you figure out how to get an input from the query string or a form on the page reply to this topic!
If need be, you can also use .asp but its not the same ASP code I'm familiar with, its different.. but maybe it can be used to receive parameters from the query string and subsequently run commands on the router.
The thing is I tried doing exactly the same - no success. It just doesn't run!
What firmware do you use? I'm running DD-WRT v23 SP3 mini
I believe that when I manage running .cgi or .sh script, I can easily rename it into .php and put outside cgi-bin directory?
David, it's really strange, but now I just tried with .sh - and it worked! I downloaded a text file with 'hell world' inside it!
could it be because of ';' sign at the end of the first line? when I removed it and run my script.cgi - it also worked fine, at least within cgi-bin directory.
what do you mean by php parser?
I just need a simple sh script named script.php
although, now I am not that sure it will help me - now I need busybox get a small web-page from Internet and give it back to me through the web-server.
btw, can you point me to any .asp scripts on the router's file system? the thing is they should parse urls! probably, they use the same http environment as cgi.
Sorry buddy, can't really find any. Plus everything goes to apply.cgi which is internal to the router.. this was really the end of the line for me. You know everything I do right now.
It seems I get it. Look what I did. I put a line
echo "+ ARGS: ${0}"
into my script. When I run it I got the name of my script. Then when I tried adding test.cgi?param=1 I got an error. May be the variables are sent using post method and the server checks that all the requests end with .cgi, .html, .htm - then, it's no good for me, I'd have to go for kamikaze...