My process name is test
. If I use
ps -ef | grep test
I see that process is running. Now I want to check this every 10 mins for one hour and print success if it's running successfully for one hour. What is the best way to do so?
My process name is test
. If I use
ps -ef | grep test
I see that process is running. Now I want to check this every 10 mins for one hour and print success if it's running successfully for one hour. What is the best way to do so?
You can use a
while
loop; here i am usingpgrep
to check if the process is running:Replace
<process_name>
with the actual name of the process you want to track.A simple loop in a script:
SECONDS
is a special variable in bash that contains the number of seconds since the script has started.pgrep test
checks for a process namedtest
. If it doesn't find one, we exit the script. If not, wesleep
for 10 minutes.If we didn't exit, then
pgrep
was successful. So,echo success
.