Tuesday, February 20, 2007

doafter

The following script will wait for the exit of a certain process (by pid) and will run a command after the exit of the watched process. It works by polling for the existence of the directory in /proc representing the given pid. After that directory is gone it runs the supplied command. It checks every 10 seconds. It exits returning an error if the pid doesn’t already exist.




#!/bin/bash
## doafter - by Jason Mansfield - http://clinicallyawesome.com/

if [ "${2}" = "" ]
then
echo "Usage: doafter "
exit -1
fi

WATCHPID=${1}

if [ ! -d /proc/${WATCHPID} ]
then
echo "No such process: ${1}"
exit -1
fi

shift

while [ -d /proc/${WATCHPID} ]
do
sleep 10s
done

${@}

No comments:

Post a Comment