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

I realize this is more of a techical question but I know someone here has used perl for a cronjob on their web server before.

I have a script that doesn't collect any data, it just loads pages. All it does is print a few things to the screen (which would be discarded when it's in CGI format as I won't care about any of the output).

Question is, is it possible to run a perl script that doesn't take much memory for days on end? Or like CGI files, would there be a timeout if the script doesn't complete in enough time?

I just want to keep a script running on my web host for a few days, think it's possible?

Replies are listed 'Best First'.
Re: using perl for a cron job
by Zaxo (Archbishop) on May 24, 2006 at 18:29 UTC

    Do you want to run it continually, or periodically?

    For the latter, cron is what you want. See man crontab for how to set it up. You can give the crontab more or less the same command line you would use in a terminal session.

    For continuous running, your script needs to be written to do that. One way is with Proc::Daemon, and an endless loop.

    After Compline,
    Zaxo

      I'd like to run the script once a day and self-kill it if it's possible. It just loads pages and pages and pages nonstop and it literally takes about 3 days to finish, but I'd restart it once a day.

      It doesn't use any files outside of the perl script itself, it's a simple little script using a while loop that takes about 3 days to finish.

Re: using perl for a cron job
by samtregar (Abbot) on May 24, 2006 at 18:27 UTC
    Simple answer: yes - long running Perl processes are definitely possible. Long answer: yes, but consider what might happen if your long running process is started while a previous run is still happening. You can avoid this using lockfiles or pid-files, for example. You might also find Proc::Daemon useful to get your program running without a terminal (although if you use cron to launch it you won't have to do this).

    For an example of a long-running Perl daemon you could look at Krang's scheduler and FTP daemons.

    -sam

Re: using perl for a cron job
by GrandFather (Saint) on May 24, 2006 at 18:26 UTC

    Yes.


    DWIM is Perl's answer to Gödel
Re: using perl for a cron job
by izut (Chaplain) on May 24, 2006 at 18:36 UTC

    cron allows you execute long running jobs, but it's safer that you handle the timeouts of your application by doing something like that:

    $SIG{ALRM} = sub { die "Game over!"; } alarm(10); sleep(20);

    More info on perlipc.

    Igor 'izut' Sutton
    your code, your rules.