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 piping
stdout) through to whats inside the parenthesis
logger -s -t "$(basename "$0")")the
loggerprogram is a means of piping output into your systems
rsyslogor what have you.
basenameadds the file/scripts name onto the syslog entry.
2>&1is for piping
This information was wonderfully pulled from UrbanAutomation’s website.