Hi,
I need to monitor a log file for a certain string ("Phase 2 ended") which indicates that the job which creates the log file has finished loading its data file. Once the string "Phase 2 ended" is found in the log file I would then like to stop checking that log and check to see if another logfile has been started - and start the whole process over.
Here's what I have so far ...
#!/bin/ksh
# Get name of the newest logfile
LogFile=`ls -tr /path/logfilename_* | tail -1`
if grep 'Phase 2 ended' $LogFile
then
echo ----------
echo "File has finished processing. No file currently being loaded."
echo ----------
else
echo
echo ----------
echo "File still being loaded. Will monitor progress, watch for \"Phase 2 ended\" message."
echo ----------
#Show all 'Phase' messages in log file so far...
grep 'Phase' $LogFile
#Keep checking so 'Phase 2 ended' message can be seen...
tail -f $VAULogFile | grep Phase
fi
Now, of course, the above does not exit when it reaches 'Phase 2 ended' or the end of the file - it just sits there, in the way tail -f does.
I think I need a while read, so I can stop the tail -f and then loop to the next log file (if one yet exists) but I don't know how to do it.
Could one of you experts please point me in the right direction?
Many thanks
--
Jake