Last active
March 6, 2018 22:27
-
-
Save stefanlasiewski/1791db468d87e9b7d43bc74a2a277119 to your computer and use it in GitHub Desktop.
Easy logging for any bash script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# A handy way to redirect script output to syslog | |
# Way more granular then adding a bunch of `/usr/bin/logger` stanzas | |
# Thanks to http://urbanautomaton.com/blog/2014/09/09/redirecting-bash-script-output-to-syslog/ & | |
# Eric at https://twitter.com/lindvall/status/509054237267853312 | |
echo "writing to stdout, before the I/O redirection" | |
# Prints to the screen and to syslog | |
exec 1> >(/usr/bin/logger -s -t $(basename $0)) 2>&1 | |
echo "writing to stdout" | |
echo "writing to stderr" >&2 | |
# Prints to syslog, but not to the screen | |
exec 1> >(/usr/bin/logger -t $(basename $0)) 2>&1 | |
echo "writing to stdout, not to the screen" | |
echo "writing to stderr, not to the screen" >&2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment