Skip to content

Instantly share code, notes, and snippets.

@shurain
Created April 24, 2013 06:39
Show Gist options
  • Save shurain/5450093 to your computer and use it in GitHub Desktop.
Save shurain/5450093 to your computer and use it in GitHub Desktop.
Watch for a particular pid and execute the command when the given process terminates. Useful when used together with notification system. $ ./waitforit.sh [PID] [CMD]
#!/bin/bash
delay=5
pid=$1
cmd=$2
status="0"
while [ "$status" == "0" ]
do
sleep $delay
ps -p$pid 2>&1 > /dev/null
status=$?
done
#The process has started, do something here
$cmd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment