How can I wait for certain output from a process then continue in Bash?

I had to do something similar waiting for a line in /var/log/syslog to appear. This is what worked for me:

FILE_TO_WATCH=/var/log/syslog
SEARCH_PATTERN='file system mounted'

tail -f -n0 ${FILE_TO_WATCH} | grep -qe ${SEARCH_PATTERN}

if [ $? == 1 ]; then
    echo "Search terminated without finding the pattern"
fi

It pipes all new lines appended to the watched file to grep and instructs grep to exit quietly as soon as the pattern is discovered. The following if statement detects if the ‘wait’ terminated without finding the pattern.

Leave a Comment

techhipbettruvabetnorabahisbahis forumu