This question already has an answer here:
#!/bin/bash sudo tail -fn0 /home/main/time.log | grep -o --line-buffered 'garage\|garden\|porch' | head -1 | while read line; do sudo pkill -f porch.sh & sudo pkill -f garage.sh & done
I'm trying to write a script that monitors a log, and upon matching a keyword, it will fire off some commands.
Problem is, what I've pieced together will work only once, then exit and stop monitoring.
I have "head -1" added to grep, because I want this to execute after the first keyword only, and prevent it from executing a multitude of times should multiple keywords appear in the tail of the log. So, basically, If multiple keywords appear in the tail, I want it to execute at the first keyword, ignore the rest of the keywords, execute the scripts listed, then go back to monitoring the tail of the log.
I would prefer the script to remain active after it matches a keyword and continue monitoring the tail of the log for any new keywords that might get logged.
Any advice is much appreciated. Thank you!