git alias
[hband-tools.git] / user-tools / loggerexec
blob359d92506bd7156b5f8eff03d2f74bcf8d8b095c
1 #!/bin/bash
3 true <<EOF
4 =pod
6 =head1 NAME
8 loggerexec - Run a command and send STDOUT and STDERR to syslog
10 =head1 SYNOPSIS
12 loggerexec [-s] I<FACILITY> I<IDENT> I<COMMAND> [I<ARGS>]
14 Send I<COMMAND>'s stdout and stderr to syslog.
15 I<FACILITY> is one of standard syslog facility names (user, mail, daemon, auth, local0, ...).
16 I<IDENT> is a freely choosen identity name, also known as tag or programname.
17 I<COMMAND>'s stdout goes as B<info> log level, stderr goes as B<error> log level.
18 Option C<-s> puts the output on stdout/stderr too.
20 =head1 SEE ALSO
22 logger(1), stdsyslog(1)
24 =cut
26 EOF
29 if [ ".$1" = ".--help" ]
30 then
31 pod2text "$0"
32 exit
35 declare -a logger_opts=()
37 if [ "$1" = -s ]
38 then
39 logger_opts+=(-s)
40 shift
43 set -e
44 set -o pipefail
45 set -u
47 facility=$1
48 shift
49 ident=$1
50 shift
52 exec "$@" > >(exec logger -p "$facility.info" -t "$ident" "${logger_opts[@]}" 2>&1) 2> >(exec logger -p "$facility.error" -t "$ident" "${logger_opts[@]}")