Futuregeek Futuregeek - 5 months ago 33
Perl Question

Run Perl script 1 minute interval without CronTab

My Perl script(test.pl) is now running in crontab as

* * * * * perl test.pl >/dev/null 2>&1

I wish to run my script every 1 minute inteval without using crontab. I will not have access to write cron jobs into /etc/cron.d/, so need to find an another solution

Is there any way to do this?


Schedule::Cron is a module on CPAN, which provides powerful abilities to run periodical tasks.

use Schedule::Cron;
my $cron = new Schedule::Cron(sub {});
sub run_task { 
    # do something... 
$cron->add_entry("0 11 * * Mon-Fri",\&run_task);

It is highly recommended because:

  1. The time interval to trigger a task is customized and flexible, almost the same as crontab in *nix systems. So you could change your script when you have new requirements easily and fast;

  2. Instead of run the whole script periodically, it allows to run a single function in your script periodically, so again, flexible;