I need to write a script that will tail a log and look for a specific message. When the message appears, the script needs to continue to monitor the log, and when the message has not appeared again for 5 seconds, I need the script to execute a command.
Here's the pseudo code:
tailing log file Found message "an error occurred" The message repeats anywhere from 10 to 20 times. Once the message has stopped scrolling, wait 5 seconds and execute "systemctl restart myservice"
I was trying to use awk, but I'm having trouble figuring out how to wait until the message stops scrolling before I execute the command. Here's the code I had:
tail -F /var/log/mylog.log | awk '
/TestString goes here/ { system("sleep 5; systemctl restart myservice") }'