diff --git a/syslogize.sh b/syslogize.sh new file mode 100755 index 0000000..aa4cfdf --- /dev/null +++ b/syslogize.sh @@ -0,0 +1,33 @@ +#!/bin/sh +# A wrapper for programs that can't write to syslog. Output and error +# are sent to syslog. +# +# Use LOGGER environment variable to pass options to `logger`. They'll +# probably be system-dependent, so handle with care. +# +# Usage: +# +# LOGGER="-t program" syslogize program -o -p --tions argu ments +# +# daemonize /usr/local/bin/syslogize program + +if test $# -eq 0 ; then + grep "^#" $0 | grep -v /bin/sh | sed -re "s/^#\s*//" >&2 + + exit 1 +fi + +LOGGER="${LOGGER:--t $1}" + +propagate_signal () { + logger ${LOGGER} "Received $1 signal" + jobs -p | xargs kill -$1 +} + +for signal in HUP INT QUIT USR1 USR2 TERM; do + trap "propagate_signal ${signal}" ${signal} +done + +$@ 2>&1 | logger ${LOGGER} & + +wait $!