I am not an expert in scripting, still learning but I want to create a script in linux that monitor log file, with every line output on logs, search for a keyword and if matched execute the given command and continue monitoring the log file. I wrote a script for this kind of behaviour (sort off) but this will grep the logs from start again after the condition is met. I do not want to start from top in next iteration, I want the script to continue from the the last matched position Here is the script i am using:
#!/bin/sh
while true ; do
grep -q "$1" /path/to/log_file.log
if [[ $? == 0 ]]; then
//run my command here
else
printf .
sleep 1
fi
done
Any help is appreciated. Thanks.