Here code that doesn't use
at but
sleep; it doesn't need external storage of data but runs continuously.
Wat i suggest is to log evrything in the beginning by echoing the variables to the logfile, mainly the Delay to see if you have to adjust the tolerance at another value.
I let you code the different logs you want to make (i can help u) but try first the functioning of the script. You can add lines for monitoring purpose by echoing commands or start the script with the -x parameter like
bash -x simple.sh
Code:
#!/bin/bash
File1=simple.txt # The file to check
LogFile=simple.log # The log file
DelayMax=30 # Timeout delay
Tolerance=2
# BEGIN ##############################
while true
do
StampNow=$(date +%s)/60 # stamp in minutes
StampFile=$(date -r "$File1" +%s)/60
let Delay=$StampNow-$StampFile
if [ $Delay -gt $DelayMax ]
then
echo "$(date) : ERROR : Timeout" >> $LogFile
# etc.
exit 1
elif [ $StampFile -eq $StampOld ]
then
sleep $Tolerance minutes # Retry a bit later
else
StampOld=$StampFile
let NewDelay=$StampNow-$StampFile+15+$Tolerance # To synchronize with the updating
sleep $NewDelay minutes
fi
done