jonnyfolk has asked for the wisdom of the Perl Monks concerning the following question:

I have a script on a server for which I do not have the facility of setting up a cron job. The script in question simply does some house keeping and I simply need to call the script from my browser to activate it.

I set up a script on a server where I do have cron using Location: to call up the housekeeping script.

#!/usr/bin/perl -w use strict; use CGI ':standard'; my $target = "http://www.mysite.com/cgi-bin/cd.pl"; print "Location: $target\n\n";
However this doesn't do the trick as in calling the script itself - it simply emails me with the URL! (Which at least reminds me to do it :))

How can I call the script in such a way as to make it run automatically?

Replies are listed 'Best First'.
Re: calling a script from another using cron
by Corion (Patriarch) on Feb 08, 2004 at 10:11 UTC

    This is not how http works.

    Your cron script will need to make a http request to your other server and trigger the worker script there. The easiest way is to use LWP::Simple :

    use strict; use LWP::Simple; my $url = 'http://www.example.com'; get $url or die "Couldn't retrieve $url";

    Your script simply did one thing, as you witnessed already, it just printed out the location, which does not accomplish anything unless you are a browser that interprets the Location: header as something to act upon...

      Many thanks - I hadn't realised that Location: was for browser interpretation. Should've, of course - Doh!

      Qick'n'easy fix, too...

Re: calling a script from another using cron
by davis (Vicar) on Feb 08, 2004 at 10:12 UTC

    However this doesn't do the trick as in calling the script itself - it simply emails me with the URL
    Of course it does. Look at what your script does - it only prints a text string.
    You want it to masquerade as a browser - use LWP::Simple (there are many, many other choices as well).
    #!/usr/bin/perl use warnings; use strict; use LWP::Simple; my $target = "http://www.mysite.com/cgi-bin/cd.pl"; $content = get($target); #Actually send the request to the webserver die "Couldn't get $target!" unless defined $content;


    davis
    It's not easy to juggle a pregnant wife and a troubled child, but somehow I managed to fit in eight hours of TV a day.
      Or you could simple make use of the GET utility that comes with LWP, and put
      * * * * * /path/to/GET http://www.mysite.com/cgi-bin/cd.pl > /dev/ +null
      in the crontab file. No additional program needed.

      Abigail