I have a file that I want to monitor.
Whenever a certain word is added to the end I want to be notified.
I have figured out how to do it manually... ie:
tail /path/to/file/TransferLog.txt | grep Total
When I type this in - I get no output if the word 'Total' is not yet there - and I see the line printed out when it is found.
So far so good.
What I'd like to do is set this 'watching' in motion - have it check every 5 minutes or so until the word 'Total' shows up - then, stop checking and shoot me an email - or other desktop notification (that part I have figured out) - it's the starting and repeating the check that I am unsure how to do.
I am running this on /bin/bash
Thanks for any advice (or keywords to search)
Some parts of the following script are a bit sketchy but the logic should be clear:
#! /bin/bash
pAction()
{
mail -s "Subject goes here" you@youraddress.com <<-EOT
Some text
This is the found line: \"$1\"
This is some command output: $(date)
EOT
return $?
}
# main()
typeset chLine=""
typeset fWatch="/Volumes/Cache-A/TransferLog.txt"
tail -f -n 2 $fWatch | grep "Total" |\
while read chLine ; do
pAction "$chLine"
done
exit 0