Skip to content

Instantly share code, notes, and snippets.

@kiriakos
Created June 8, 2012 09:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kiriakos/2894742 to your computer and use it in GitHub Desktop.
Save kiriakos/2894742 to your computer and use it in GitHub Desktop.
rudimentary daemonize (push a command through an infinite loop)
#! /bin/bash
## Daemonizes $1 (calls it in an infinte loop)
#
# If you need to pass arguments to the executable pass freely after the command
# eg:
# /usr/local/sbin/sorta-daemonize echo -e "\thello"
LOG="/var/log/sorta-daemonize.log"
#basic validation
[ $# -lt 1 ] && { echo "you must call this with a valid program/script as a parameter" > $LOG; exit 1; }
type $1 >/dev/null 2>&1 || { echo `date`" Error: $1 does not exist or is not executable. Aborting." > $LOG; exit 1;}
while [ true ]
do
$@
sleep 5
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment