I stumbled across this link: "watch" the output of a command until a particular string is observed and then exit
I know the PID of the process. I want to log the process "resource-consumption" using top.
Basically top -p PID -b >> LOGFILE.
I want to have this run in increments, say every 5 seconds using the "watch" command
watch -n 5
From an independent/external program, I will append "We Are Finished" to the logfile.
I want the logging of watch/top to break/exit when "We are Finished" So grep should be evaluating the entire log file, not just the current value.
I want the command to run in a nonblocking form... maybe ends with " & "
I set -d to 5 so top and watch are creating at the same time? ...
Here is my attempt using the "-e" option suggested from the link above, not working as expected... PID and LOGFILE are appropriate values.
watch -n 5 -e "! top -d 5 -b -p PID >> LOGFILE | grep -m 1 \"We Are Finished\"" &