Bash Logging
tl;dr:
exec 1> >(logger -s -t "$(basename "$0")") 2>&1
Been looking for a way to pipe your entire bash script into a log file, syslog, journald, or whatever? The above line does it super simply!!
This was a line I had found a few years back, started learning ansible, and lost this nugget of knowledge, and recenlty found it once again (but lost the website I found it from… Sorry!)
What does it do?
exec: this line tells bash “you are to run everything”1> >(this sets up piping1(stdout) through to whats inside the parenthesislogger -s -t "$(basename "$0")")theloggerprogram is a means of piping output into your systemssyslogorrsyslogor what have you.basenameadds the file/scripts name onto the syslog entry.2>&1is for piping2orstderrinto theexeccommand
This information was wonderfully pulled from UrbanAutomation’s website.