Futuregeek Futuregeek - 1 year ago 83
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?

Answer Source

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;

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download