I have been facing a very peculiar issue with shell scripts.
Here is the scenario
Script1 (spawns in background)–> Script2
Script2 has the following code
function check_log()
{
logfile=$1
tail -5f ${logfile} | while read line
do
echo $line
if echo $line|grep "${triggerword}";then
echo "Logout completion detected"
start_leaks_detection
triggerwordfound=true
echo "Leaks detection complete"
fi
if $triggerwordfound;then
echo "Trigger word found and processing complete.Exiting"
break
fi
done
echo "Outside loop"
exit 0
}
check_log "/tmp/somefile.log" "Logout detected"
Now the break in while loop does not help here. I can see “Logout completion detected” as well as “Leaks detection complete” being echoed on the stdout, but not the string “outside loop”
I am assuming this has to do something with tail -f creating a subshell. What I want to do is, exit that subshell as well as exit Script2 to get control back to Script1.
Can someone please shed some light on how to do this?
Try this, although it’s not quite the same (it doesn’t skip the beginning of the log file at startup):
The double loop effectively does the same thing as
tail -f.