That's how i started doing this too but have become much more sophisticated with it. A couple things to be concerned with:
- If the tail of the log already contains "server is up".
- Automatically ending the tail process once it's found.
I use something along the lines of this:
RELEASE=/tmp/${RANDOM}$$
(
trap 'false' 1
trap "rm -f ${RELEASE}" 0
while ! [ -s ${RELEASE} ]; do sleep 3; done
# You can put code here if you want to do something
# once the grep succeeds.
) & wait_pid=$!
tail --pid=${wait_pid} -F /path/to/serverLog \
| sed "1,10d" \
| grep "server is up" > ${RELEASE}
It works by holding tail open until the ${RELEASE} file contains data.
Once the grep succeeds it:
- writes the output to
${RELEASE} which will
- terminate the
${wait_pid} process to
- exit the
tail
Note: The sed can be more sophisticated to actually determine the number of lines tail will produce at startup and the remove that number. But generally, it's 10.