I have a monitor script that executes every 5 minutes. I am adding functionality that will detect if a previous execution is hung. I have managed to do that by using a flag that is created when the monitor starts and is then removed when the monitor finishes. The hang check simply looks to see if the flag exists and if it does, trigger an alert. Problem is, if a monitor hangs, every subsequent execution shoots off an alert every 5 mins (that's 96 alerts in the morning if it hangs just after I go to bed...)
So, what I need is a second test that will check to see if the flag is older than 1 hour. That way I'll get the initial alert and then one every hour after that instead of every 5 mins. I need a simple condition for my script:
if [ -a monitor_running_flag ]
then
if [ -a hung_monitor_flag ]
echo "alert fired already"
else
echo "previous execution of monitor might be hung"
touch hung_monitor_flag
fi
fi
if [ monitor_running_flag older than 1 hour ]
then
echo "monitor still hung, check on it"
fi
I need something for: [ monitor_running_flag older than 1 hour ]
Thanks!