I'm looking for a bash script that checks if the Installer process is running and waits/pause if it then proceeds once the process is no longer running.
Here is what I have so far:
#!/bin/bash
PROCESS="Installer";
PID=$(ps -A |grep -m1 "$PROCESS" | awk '{print $1}');
while s=`ps -p $PID -o s=` && [[ "$s" && "$s" !='Z' ]]; do
echo "$PROCESS is Running, waiting for it to close"
sleep 1
done
echo "$PROCESS is not Running";
SCRIPT HERE
Best Answer
I took your script and changed
pgrep
-o s=
to-o stat=
forps
;
at the end of some linesIt's a bit hard to test, but something like
should work.
If you are not worried about the Installer getting into Zombie state you could rely on the fact that
ps
exits with 1 if no process is found, and significantly simplify the loop condition.