Created
July 26, 2013 18:08
-
-
Save solidsnack/6090947 to your computer and use it in GitHub Desktop.
Wrapper for logging any command's STDOUT and STDERR to syslog.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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