Auto-magically log all output or your script to syslog

An Rodriguez
1 min readFeb 17, 2020

--

All output from the script is automatically sent to syslog.

Not long ago I stumbled upon this solution to automatically send all output of a bash script to syslog.

All you have to do is add the command at the beginning of the script and all following output will be written to syslog along with the script name.

The solution uses the logger interface to syslog.

The line is

exec 1> >(logger -s -t $(basename $0)) 2>&1

For example, say we have this executable bash script and we name it autolog.sh:

If we execute it and then see syslog we get:

I took this solution from here: http://urbanautomaton.com/blog/2014/09/09/redirecting-bash-script-output-to-syslog/, but the URL is currently broken.

Do you have any tips for logging on bash? Let me know!

--

--

An Rodriguez

Yet another self-appointed dialectical logicist, coder, fundamental physicist, artist, and dad, among others. More about me: https://about.me/anrodriguez