I have a bash that has 2 while loops, the first is an infinite loops that tracks some events, and the second reads a log file and does something when a specific line shows up:
#!/bin/bash
while [ 1 ]; do
...
done &
date=`date +%Y%m%d`
file="logs/$date.log"
tail -f $file | grep --line-buffered "ALERT" | while read line
do
...
done
This works great, my only issue is that each day after 00:00 the log rotates to a new day (this is sadly out of my control), how can I rerun the second while loop at 00:01 ? (log rotation is at first write but I don't mind losing a minute)
Using cron to kill everything and restart is not great because it also kills my first loop, so I was thinking there must be an intelligent way to do this from inside the script.