new tool
[hband-tools.git] / user-tools / loggerexec
bloba35189443f70301f94ab0abf28e8913e2a69c9dd
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 passthrough=''
37 if [ "$1" = -s ]
38 then
39 passthrough=1
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 {fd}>&1; exec tee ${passthrough:+/dev/fd/$fd} | exec logger -p "$facility.info" -t "$ident" 2>&1) 2> >(exec tee ${passthrough:+/dev/stderr} | logger -p "$facility.error" -t "$ident")