If you're only looking for one possibility and want to stay mostly in the shell rather than using awk
or perl
, you could do something like:
tail -F /path/to/serverLog |
grep --line-buffered 'server is up' |
while read ; do my_command ; done
...which will run my_command
every time "server is up" appears in the log file. For multiple possibilities, you could maybe drop the grep
and instead use a case
within the while
.
The capital -F
tells tail
to watch for the log file to be rotated; i.e. if the current file gets renamed and another file with the same name takes its place, tail
will switch over to the new file.
The --line-buffered
option tells grep
to flush its buffer after every line; otherwise, my_command
may not be reached in a timely fashion (assuming the logs have reasonably sized lines).
tail -F
to handle log rotation - i.e.my.log
becomes full and moves tomy.log.1
and your process creates a newmy.log