#!/usr/bin/perl use strict; use warnings; my $HOUR = (localtime(time))[2]; # $HOUR = '0'.$HOUR if $HOUR<10; # make it a 09 instead of 9 my $RUNFILE = "/tmp/minimon.run"; my $ERRORSTATE = "/tmp/minimon.error"; my $lastrun = -f $RUNFILE ? (int( (-M $RUNFILE) *60*60*24) || 1) : 0; # Seconds ago it has run. (or 1 if less than 1) # touch early to avoid bordercases (we rather check double than not) if(open(FF, ">", $RUNFILE)){ close FF; }else{ warn "Could not open $RUNFILE, $!"; } my $IN_FILE = "/tmp/raid/logs/$HOUR"; if (-f $IN_FILE){ my $fileage = -M $IN_FILE; if($lastrun > $fileage){ print "File $IN_FILE has not been updated, no action"; exitOK(); }else{ # loop through file here and determine exitERROR() or exitOK() } }else{ warn "No RAID files? I expected $IN_FILE"; } my $cmd = "cat /raid/logs/`date +%H`"; my $out_file = "/home/resource/certchange.txt"; sub exitOK{ unlink $ERRORSTATE if -f $ERRORSTATE; exit 0; } sub exitERROR{ if(-f $ERRORSTATE && ( -s $ERRORSTATE eq $HOUR) ){ warn "Already reported an error in $IN_FILE"; return 0; } if(open(ERR, ">", $ERRORSTATE)){ print ERR "." x $HOUR; close ERR; }else{ warn "Could not open ERRORSTATE $ERRORSTATE $!"; } # do email thing here exit 0; }