Thanks! I needed a way to respawn a service which is normally started by a debian style script in /etc/init.d during boot because I think there is no builtin way to respawn processes ... unless I convert the script to an Ubuntu upstart job but that's too much hassle. I changed and added some things to your script to suite my tastes.
By the way, is there a clause or directive I can put into a debian script such as /etc/init.d/vncserver to poll the running process and restart it if it stops?
# This script is a simple respawn daemon for those of us who dont want
# to deal with the /etc/event.d, monit etc...
# file: respawn.sh
# usage: /path/respawn.sh [program name] [sleeptime]
# the next example will start and respawn a text
# editor after a 5 seconds delay when it closes
# example: /path/respawn.sh gnome-text-editor 5
# when the program closes, logger will display a message in a terminal
# and log the message including the programs PID to the syslog service
# (see file /var/log/syslog)
if [ "$1" == "" ] || [ "$2" == "" ]; then
echo error: not enough parameters given.
echo usage: respawn.sh [program name] [sleep time]
while [ true ]
if ps ax | grep -v grep | $PNAME > /dev/null
logger -i -s -t respawn.sh "$PNAME stopped. Restarting in $STIME seconds."