Auto-magically log all output or your script 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!