Forum Moderators: coopster & phranque

Message Too Old, No Replies

Execute remote script via cron

I have a Cold Fusion script I need to execute via PERL cron

         

kingzeus

8:23 pm on Dec 29, 2003 (gmt 0)

10+ Year Member



Okay, here's the situation. I have a Cold Fusion script and I need to execute every hour. However, this is a very time consuming script that every hour will transfer files anywhere from 0 to 30+ FTP sites. I have some limitations in that hosting environment that prevent the script from executing longer than 20 seconds.

So my solution is to run a PERL script that loads the URL to the CGI Script every hour via CRON. This is the code I have now that is not working:


#!/usr/local/bin/perl
alarm (300);
$url = "http://[MySITE].com/file.cfm?RequestTimeout=300";
print "Location: $url\n\n";
exit;

Does the Location tag not work because a web browser is not calling the script? I'm sure there is a very simple solution. I just have not found it. Thanks for any help.

volatilegx

8:31 pm on Dec 29, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Does the Location tag not work because a web browser is not calling the script?

Yep. The Location: header simply sends a redirect header to the browser. Since no browser is involved (just a cron job), the Location: header doesn't do anything besides waste CPU cycles.

I'd recommend using LWP to call the script, like this:

#!/usr/local/bin/perl
alarm (300);
$url = "http://[MySITE].com/file.cfm?RequestTimeout=300";
use LWP::Simple;
$foo = get $url;
exit;

kingzeus

9:08 pm on Dec 30, 2003 (gmt 0)

10+ Year Member



Thanks a lot. You lead me in the right direction. This is the script I ended up writing:
#!/usr/local/bin/perl
alarm (300);
require LWP::UserAgent;
$ua = LWP::UserAgent->new;
$ua->timeout(300);
$request = HTTP::Request->new('GET', 'http://www.[MySite].com/file.cfm?RequestTimeout=300');
$response = $ua->request($request);

volatilegx

10:16 pm on Dec 31, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Glad I could help, and welcome to WebmasterWorld :)