I want to monitor a log file for a particular change, so, I was thinking I would do:
However, while grep does exit, the tail process is left open. So, what I ended up doing was using a named pipe, but this is only marginally better, because it doesn't work without the while loop:
I should also state that the named pipe doesn't solve the problem, I have to get the PID and then ultimately kill it which I do (outside of the code shown here).
This is a bit hackish and I was hoping for a better way to achieve this. The while loop is also not efficient, so I'd like to remove that if possible.
Code:
tail -f <LOG_FILE> | grep -m 1 "SOME PATTERN"
However, while grep does exit, the tail process is left open. So, what I ended up doing was using a named pipe, but this is only marginally better, because it doesn't work without the while loop:
Code:
while [ 1 ]; do
grep -q -m 1 "SOME PATTERN" <NAMED_PIPE>
if [ $? -eq 0 ]; then
break
fi
# try to be somewhat less resource intensive
sleep 1
done
I should also state that the named pipe doesn't solve the problem, I have to get the PID and then ultimately kill it which I do (outside of the code shown here).
This is a bit hackish and I was hoping for a better way to achieve this. The while loop is also not efficient, so I'd like to remove that if possible.