I'm having a problem with my bash script about breaking out a nested while loop that reads a line from a logfile with tail.
What i need: The nested while loop that reads the logfile should find some regex. If that's true save it to a variable and break out the loop. Outside the loop there is a other while loop that checks if it's time to send some data over to a Confluence page. If it's not the time yet do nothing until a line is found in the while loop that is true to the regex.
I made a MVCE:
#!/bin/bash
counterSearch=0
tail -n0 -f $logfile | {
while true; do
currentMinute=$(date +%S)
# Checks if $currentSecond is set to 59. If true do something.
# Else go back to while loop.
if [[ $currentSecond -eq 59 ]]; then
echo "Hello. This is 59 seconds outside while read line loop"
fi
# This while loop should always check if in the $logfile a specific line if found.
# If true save it and go back to the outside while loop. When a new line is found
# execute it again.
while read line ; do
if echo "$line" | grep -e "/rest/api/2/search.*PASSED" 1>/dev/null 2>&1 ; then
echo "$date - Search and passed API action" >> $log
counterSearch=$((counterSearch+1))
fi
done
done
}
The problem is that the keeps running the inner while loop. If doesn't break out to the outer while loop. I already tried it with functions and a function with an if/else that calls one or the other loop.