I have a file name like simple.txt which comes from Mainframe systems onto windows dir every 15 minutes daily. File name is same. Every 15 minutes it updates.
I need to write shell script to check if the file arrived every 15 min or not.
If the new file has not arrived after 30 min, I need to exit and send message and also generate log file with start-time and end-time.
At the end of the day I also need to generate another log with Start time and end-time as fields.
A self sheduling script (by using at) seems me the best. I use such a procedure to get hourly satellite images from a website)
# if the file has been updated (if the datestamp is newer than the previsously saved one)
# then save it and get the datestamp
# calculate the difference between actaul time and datestamp
# if the difference is too big (i.e. > 30 minutes) exit, error, report in logfile etc.
# calculate the time of the next check (15 minutes + 1 or 2 minutes delay depending on the precison of the update time and the delay between timestamp and availability of the file) (That will synchronize the checking with the updating)
# activate the differed launching of this script
# report in logfile
The advantage of at is that if the system is down at sheduled time it will launch the script at the next startup (not possible with cron)
Do tou have other suggestions ?
I can code that in bash if needed but yo
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
#!/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