Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

crontab

Status
Not open for further replies.

f117bomb

MIS
Nov 24, 2001
13
US
How can you use crontab to exec a cgi script WITH query string. If this can't be done with crontab then how can i achieve the same goal?
 
That depends on how the cgi script reads its data. If it uses GET, you just pass the arguments on the command line using spaces to separate them (as opposed to the "?"'s you would use if coding from a web page).

If it's POST, you set and export the environment variable CONTENT_LENGTH and then feed your data to the standard input of the process; like this in shell:

export CONTENT_LENGTH=5; echo "12345" | cgi_script

Of course "12345" is probably not what the cgi script expects. Generally it would be pairs of data separated by ampersands, like this

myname=tony&mycolors=red&today=Sunday

So you do need to know what the cgi script is looking for, Usually you can determine that from the web form that it ordinarily uses.

You also need to understand that certain characters (like spaces) need to be encoded. Spaces are easy: you use "+"

sentence=this+is+a+sentence&word=fred

but other things have to be translated to hex and preceded by a "%". Here's an example of multiline input:

name=Fred+Jones&address=10+Sample+street%0D%0AApt+8

Hope that gets you started at least.

Tony Lawrence
SCO Unix/Linux Resources tony@pcunix.com
 
Wow that’s incredibly helpful. Thanks


By the way do you know where I can find a Hexadecimal chart or converter on-line?
 
We can't possibly have any more ideas without seeing the cgi script itself. Tony Lawrence
SCO Unix/Linux Resources tony@pcunix.com
 
I didn't realize that you wrote the script, sorry.

Rather than reinventing the wheel, you should use the CGI.pm module for getting the input. Much easier.

But I'll take a look at your code more closely in a little bit..

Tony Lawrence
SCO Unix/Linux Resources tony@pcunix.com
 
OK, I see what you did wrong.

You would need to do this:

export REQUEST_METHOD=POST;export CONTENT_LENGTH=62; echo "datafile=%2Fvar%2F | /var/

Or:

QUERY_STRING="datafile=%2Fvar%2Fexport QUERY_STRING
var/
That's all because of the unusual way you wrote your code. Had you wrote it differently, or had you used CGI.pm, this wouldn't be necessary.



Tony Lawrence
SCO Unix/Linux Resources tony@pcunix.com
 
Great, ill check to see if I can get it to work later today.


As you can probably tell I haven’t written to many CGI scripts. Actually this is my second attempt at one. If I had known about CGI.pm or how to use it I would have. I just searched the web and found, what I thought, was standard way to establish query strings.
Anyways, thanks a million for all your help, all I will let you know if it works a little later.
 
ok im so lost. im now trying to use cgi.pm
all i want to do is retrieve the value in my quer string.
Here is what i got so far:

#!/usr/bin/perl
use CGI;
$query = new CGI;
print $query('test');


now if i pass test to it (test.cgi?test=1) shouldn't it return 1.

Im so lost.....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top