So when a service goes down, like apache2, etc, we want it to restart. So we use monit etc. But what happens when you simply want to respawn some GUI app when it closes, like conky or linuxdcpp?
I googled. googled and googled. Nada, zip. Wrote this script, hope it helps anyone that needs a simple solution to a simple problem.
For those of you running gnome: [System]->[Prefrences]->[Sessions]-> Startup Programs (Tab), Add (button), and under your command:
sh /path/to/script/respawn.sh [program name] [sleeptime]
so maybe:
~/scripts/respawn.sh conky 10
And now for the code.
respawn.sh:
#!/bin/bash
# This script is a simple respawn deamon for those of us who dont want
# to deal with the /etc/event.d, monit etc...
# Usage: sh respawn.sh [program] [sleep time]
while [ true ]
do
sleep $2
if ps ax | grep -v grep | $1 > /dev/null
then
echo $1": Stopped. Restarting in "$2" seconds."
else
$1 &
fi
done