Skip to content

Instantly share code, notes, and snippets.

@solidsnack
Created July 26, 2013 18:08
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save solidsnack/6090947 to your computer and use it in GitHub Desktop.
Save solidsnack/6090947 to your computer and use it in GitHub Desktop.
Wrapper for logging any command's STDOUT and STDERR to syslog.
#!/bin/bash
set -o errexit -o nounset -o pipefail
function -h {
cat <<EOF
USAGE: syslogged <program> <args>
Wraps a command invocation with logging, sending STDOUT and STDERR to
syslog, setting the syslog tag to:
<program>[<pid>]
Where <pid> is the PID of <program> (not of the logger). The syslog
priority for STDOUT is user.info; that of STDERR is user.notice.
EOF
}; function --help { -h ;}
function syslogged {
local tag="${1##*/}[$$]"
exec 1> >(exec logger -t "$tag" -p user.info)
exec 2> >(exec logger -t "$tag" -p user.notice)
exec "$@"
}
if [[ $# -eq 0 ]]
then
--help >&2
exit 1
else
syslogged "$@"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment