SH/BASH - Scan a log file until some text occurs, then exit. How??
- by James
Current working environment is OSX 10.4.11.
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 the first time, but on the second run and beyond it takes 2 occurrences of 'LOL CANDY' to appear before the script will exit, for whatever reason. 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.