Luca Luca - 1 year ago 130
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 “
”, I must exit the
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

Answer Source
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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download