tail and redirect until finding a specific word

Hey guys,
I'm a new bee to this forum as well as to Unix, just having a requirement which i'm not sure how to write shell script for it..

Here is my requirement

This is related to tomcat catalina.out file. Just want to display the content of this file until it finds a word like 'server started'. Once we get this line in catalina.out, tail -f catalina.out should be terminated. Not sure how to do it.

Any advice would be appreciated.

Thanks

#!/bin/bash

tail -f filename | while read LINE
do
        [[ "${LINE}" == *"server started"* ]] && break

        echo "$LINE"
done

if you don't have bash, ksh should work too. plain sh might not.

1 Like

Perfect! It worked well.... Thanks a lot