From: Nicolas Ross rossnick-lists@cybercat.ca
while true; do your stuff sleep 60 done;
Sure, but you also need to start the loop and make sure it doesn't die.
Put in /etc/inittab ms:2345:respawn:/path/to/my/loop_script (where "ms" is unique). If the loop dies then init will restart it for you.
I tought of that, and I will be needing something like this, since I have some services that need to be restarted in the event of them dying or being killed. But I'm not that much confortable scripting a modification of the initab to activate / deactivate services on a server-by-server basis.
I usually use a lock file and put an entry in cron (like try to relaunch the scrip every xxx in case it crashed). But that means taking care of removing the leftover lock file if the script crashed... Something like:
if [ -f "$LOCK_FILE" ]; then PID=`cat "$LOCK_FILE"` if [ ! -d "/proc/$PID" ]; then rm -f "$LOCK_FILE" if [ -f "$STOP_FILE" ]; then rm -f "$STOP_FILE"; fi exit 1 fi exit 1 else echo $$ > "$LOCK_FILE" fi
while [ ! -f "$STOP_FILE" ]; do your stuff sleep 60 done
rm -f "$STOP_FILE" rm -f "$LOCK_FILE"
JD