Luca Luca - 2 months ago 6
Linux Question

BASH Linux exit read log until specific string

I must read the log until I receive “

Server Startup
”.

When I get the string “
startup
”, I must exit the
tail
command and proceed through the rest of the script operations.

Now the syntax is:

cd /opt/path/path/path
LOG_FILE=$(ls -ltr | tail -1 |awk '{print $9}')
tail -f $LOG_FILE


Thanks in advance

PS. PS.
Answer
stdbuf -oL tail -f log.file | stdbuf -iL awk '/startup/ {print "Match found";exit}'

This will check for string startup and when it is found, it will print "Match found" and then exit from log monitoring. stdbuf to provide line buffered to tail and awk.

Comments