#!/usr/bin/perl -w use warnings; use strict; ############### # CONFIG VARS # ############### my $dir_to_watch = "/cygdrive/c/WATCHDOG"; my $timeout = 120; # Max file age (sec) my $awhile = 30; # Checking interval (sec) #-------------------------------------------------- # Sends contents of specified file to admin sub send_msg { my $fn = shift; print "You'd send $fn via EMail here...\n"; } chdir $dir_to_watch; while (1) { for (`ls`) { chomp; my $age = time - (stat)[9]; send_msg($_) if $age > $timeout; } sleep $awhile; } #### #!/usr/bin/perl -w use warnings; use strict; ############### # CONFIG VARS # ############### my $awhile = 45; # Checking interval (sec) my $my_watched_file = "/cygdrive/c/WATCHDOG/foobar"; my $EMailText= 'To: roboticus@a.fake.domain.com Subject: JobToMonitor.pl fault! Yecch! '; #-------------------------------------------------- # Let watchdog know we're alive... sub still_alive { open OF, '>>', $my_watched_file; print OF $EMailText; close OF; } unlink $my_watched_file; my $next_time = 0; my $count = 0; while ($count < 999999999999) { # put this in a part that's likely to be OK if (time > $next_time) { &still_alive; $next_time = time + $awhile; } # smallish chunks of job that shouldn't take # too much time ++$count; # You can even use it for periodic logging! $EMailText = "$count reached at " . (localtime) . "\n" if $count % 1000000 == 0; } # Don't alert if we complete successfully unlink $my_watched_file;