2 # module to timed tasks
4 # Copyright (c) 1998 - Dirk Koopman G1TLH
20 use vars qw{@crontab $mtime $lasttime};
27 my $fn = "$main::cmd/crontab";
28 my $localfn = "$main::local_cmd/crontab";
30 # cron initialisation / reading in cronjobs
36 if (-e $localfn && ($t = -M $localfn) != $mtime) {
42 if (($t = -M $fn) != $mtime) {
52 my $fh = new FileHandle;
55 dbg('cron', "reading $fn\n");
56 open($fh, $fn) or confess("can't open $fn $!");
57 @crontab = (); # clear out the old stuff
61 next if /^\s*#/o or /^\s*$/o;
62 my ($min, $hour, $mday, $month, $wday, $cmd) = /^\s*(\w+)\s+(\w+)\s+(\w+)\s+(\w+)\s+(\w+)\s+(.+)$/o;
67 $err |= parse($ref, 'min', $min, 0, 60);
68 $err |= parse($ref, 'hour', $hour, 0, 23);
69 $err |= parse($ref, 'mday', $mday, 1, 31);
70 $err |= parse($ref, 'month', $month, 1, 12, "jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec");
71 $err |= parse($ref, 'wday', $wday, 0, 6, "sun", "mon", "tue", "wed", "thu", "fri", "sat");
75 dbg('cron', "adding $_\n");
77 dbg('cron', "error on line $line '$_'\n");
98 # handle comma delimited values
99 my @comma = split /,/o, $val;
101 my @minus = split /-/o;
103 return 1 if $minus[0] < $low || $minus[0] > $high;
104 return 1 if $minus[1] < $low || $minus[1] > $high;
106 for ($i = $minus[0]; $i <= $minus[1]; ++$i) {
110 return 1 if $_ < $low || $_ > $high;
117 # process the cronjobs
120 my $now = $main::systime;
122 if ($now - $lasttime >= 60) {
123 my ($sec, $min, $hour, $mday, $mon, $wday) = (gmtime($main::systime))[0-4,6];