Edit - Reworded the question a bit on April 7th to make it clearer.
Current working environment is OSX 10.4.11.
I want to scan a log file for a certain phrase. The log file can NOT be emptied at the start of the script. Thus, the script must scan only changes to the log.
My current script:
#!/bin/sh
tail -f log.txt | while read line
do
if echo $line | grep -q 'LOL CANDY'; then
echo 'LOL MATCH FOUND'
exit 0
fi
done
It works properly in the fact that it will 'LOL MATCH FOUND' immediately after finding 'LOL CANDY', but it will not actually quit the script until there is some other addition to the log AFTER the 'LOL CANDY'. I need it to immediately quit. And although I'm not sure it is specifically related, there is the problem of the "tail -f" staying open forever. Can someone please give me an example that will work without using tail -f?
If you want you can give me a bash script, as OSX can handle sh, bash, and some other shells I think.