started the crontab stuff
authordjk <djk>
Tue, 10 Nov 1998 23:40:16 +0000 (23:40 +0000)
committerdjk <djk>
Tue, 10 Nov 1998 23:40:16 +0000 (23:40 +0000)
cmd/crontab [new file with mode: 0644]
perl/DXCommandmode.pm
perl/DXCron.pm
perl/cluster.pl
perl/connect.pl

diff --git a/cmd/crontab b/cmd/crontab
new file mode 100644 (file)
index 0000000..b2ebb38
--- /dev/null
@@ -0,0 +1,2 @@
+# crontab in normal crontab format
+#
index a0cdbb480e5e8d01212a7ebd9da634921a0cdf61..522200da3b8249cb74f3bc492a92fa1862d17331 100644 (file)
@@ -137,8 +137,6 @@ sub normal
        }
   }
        
-#    my @ans = $self->eval_file($path, $fcmd, $args) if $path && $fcmd;
-#      @ans = $self->eval_file($main::cmd, $cmd, $args) if !$ans[0];
   if ($ans[0]) {
     shift @ans;
        $self->send(@ans) if @ans > 0;
index dd78edd4ddeaf146a3c77280aa808099a1c56dfa..c31f4a92edf3dd33e5f5fc4ca96b3ce6ac9f14f8 100644 (file)
 
 package DXCron;
 
+use DXVars;
 use DXUtil;
 use DXM;
 use DXDebug;
+use FileHandle;
 use Carp;
 
 use strict;
 
+use vars qw{@crontab $mtime $lasttime};
+
+@crontab = ();
+$mtime = 0;
+$lasttime = 0;
+
+
+my $fn = "$main::cmd/crontab";
+my $localfn = "$main::local_cmd/crontab";
+
 # cron initialisation / reading in cronjobs
 sub init
 {
+       my $t;
+       
+       if (-e $localfn) {
+               if (-e $localfn && ($t = -M $localfn) != $mtime) {
+                       cread($localfn);
+                       $mtime = $t;
+               }
+               return;
+       }
+       if (($t = -M $fn) != $mtime) {
+               cread($fn);
+               $mtime = $t;
+       }
+}
+
+# read in a cron file
+sub cread
+{
+       my $fn = shift;
+       my $fh = new FileHandle;
+       my $line = 0;
 
+       dbg('cron', "reading $fn\n");
+       open($fh, $fn) or confess("can't open $fn $!");
+       @crontab = ();           # clear out the old stuff
+       while (<$fh>) {
+               $line++;
+               
+               next if /^\s*#/o or /^\s*$/o;
+               my ($min, $hour, $mday, $month, $wday, $cmd) = /^\s*(\w+)\s+(\w+)\s+(\w+)\s+(\w+)\s+(\w+)\s+(.+)$/o;
+               next if !$min;
+               my $ref = new();
+               my $err;
+               
+               $err |= parse($ref, 'min', $min, 0, 60);
+               $err |= parse($ref, 'hour', $hour, 0, 23);
+               $err |= parse($ref, 'mday', $mday, 1, 31);
+               $err |= parse($ref, 'month', $month, 1, 12, "jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec");
+               $err |= parse($ref, 'wday', $wday, 0, 6, "sun", "mon", "tue", "wed", "thu", "fri", "sat");
+               if (!$err) {
+                       $ref->{cmd} = $cmd;
+                       push @crontab, $ref;
+                       dbg('cron', "adding $_\n");
+               } else {
+                       dbg('cron', "error on line $line '$_'\n");
+               }
+       }
+       close($fh);
+}
+
+sub parse
+{
+       my $ref = shift;
+       my $sort = shift;
+       my $val = shift;
+       my $low = shift;
+       my $high = shift;
+       my @req;
+
+       # handle '*' values
+       if ($val eq '*') {
+               $ref->{$sort} = 0;
+               return 0;
+       }
+
+       # handle comma delimited values
+       my @comma = split /,/o, $val;
+       for (@comma) {
+               my @minus = split /-/o;
+               if (@minus == 2) {
+                       return 1 if $minus[0] < $low || $minus[0] > $high;
+                       return 1 if $minus[1] < $low || $minus[1] > $high;
+                       my $i;
+                       for ($i = $minus[0]; $i <= $minus[1]; ++$i) {
+                               push @req, 0 + $i; 
+                       }
+               } else {
+                       return 1 if $_ < $low || $_ > $high;
+                       push @req, 0 + $_;
+               }
+       }
+       return 0;
 }
 
 # process the cronjobs
 sub process
 {
-
+       my $now = $main::systime;
+       
+       if ($now - $lasttime >= 60) {
+               my ($sec, $min, $hour, $mday, $mon, $wday) = (gmtime($main::systime))[0-4,6];
+               
+               $lasttime = $now;
+       }
 }
 
 1;
index 07c405038e68874dc70e94938ded9045a6903f5d..d20b539c5b01447d5edc8d796752c13685e35904 100755 (executable)
@@ -236,9 +236,9 @@ for (;;) {
                $systime = $timenow;
                $cldate = &cldate();
                $ztime = &ztime();
+               DXCron::process();      # do cron jobs
                DXCommandmode::process(); # process ongoing command mode stuff
                DXProt::process();              # process ongoing ak1a pcxx stuff
-               DXCron::process();
                DXConnect::process();
        }
 }
index 99c4565b750287dd48d32326b3e4790a9b0ece36..f50c89dd2cd9ee89eee7b86032a9d2cf369e4dcd 100755 (executable)
@@ -38,6 +38,7 @@ BEGIN {
 
 use DXVars;
 use IO::Socket;
+use POSIX;
 use Carp;
 
 $timeout = 30;         # default timeout for each stage of the connect