1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
#!/usr/bin/perl
# Very simple examples which print the current
# time every 10 Minutes.
#
# The purpose is to show a common usage pattern
# using a single dispatcher subroutine provided
# at construction time
use lib "../lib";
use Schedule::Cron;
# Create new object with default dispatcher
my $cron = new Schedule::Cron(\&dispatcher);
# The cron entry which fires every 10 minutes
my $entry = "0-59/5 * * * *";
# Dispatcher subroutine called from cron
sub dispatcher {
open(T,">>timestamps.txt");
print T "Current: ",scalar(localtime),"\n";
print T "Next: ",scalar(localtime($cron->get_next_execution_time($entry))),"\n";
close T;
sleep(30);
}
# Call &dispatcher() every ten minutes
$cron->add_entry($entry);
# Run scheduler and block. 'nofork' forces the subroutine to
# be called in the main process
$cron->run(nofork=>1);
|