0
votes

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?

2
while :; do perl test.pl >/dev/null 2>&1; sleep 60s; done? - devnull
Could you explain what it is about cron that you wish to avoid? Typically running something on a schedule requires a scheduling system outside of the thing that's running. So devnull's suggestion is a long-running shell script that you could stop and start interactively. I cannot tell from your question whether this is enough - perhaps you want the script to run each minute for a few hours at a time, and wish to avoid editing crontabs in order to switch it on and off? - Neil Slater
@Neil Slater - will not have access to write cron jobs into /etc/cron.d/, so need to find an another solution - Futuregeek

2 Answers

5
votes

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);
$cron->run();

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;

0
votes

Try a daemon process. Put your code in an infinite loop and sleeps 60s between each itration. I guess.