I wrote a quick bash script that watches a log for a specific string and then exits. Except the problem is that I can still still script and its child "tail" process running after the script returns when I do a "ps -fu $user".
#!/bin/bash
####### MAIN #######
FILE=$1
MSG=""
while read LOGLINE
do
if [[ "${LOGLINE}" == *"someString"* ]]; then
MSG=${LOGLINE}
break
fi
done < <(tail -f ${FILE})
pkill -P $$ tail
echo ${MSG}
I pass it a log file from an application that is continuously being written to. When I run this script, it will find the first instance of someString, echo it to stdout and exits. Except the tail process didn't seem to get killed nor did the script itself.
tailreadily exits onSIGPIPE, this is uncessarily backwards.