Create a gist now

Instantly share code, notes, and snippets.

Embed
Redirect STDOUT and STDERR into syslog, using "logger", and bash process substitution
# Redirect STDOUT/STDERR into syslog
exec > >(logger -p user.info) 2> >(logger -p user.warn)
@shribe

This comment has been minimized.

Show comment
Hide comment
@shribe

shribe Apr 13, 2015

Nice example. It helped me figure out what I wanted to do about logging from scripts used with launchd on OS X: http://elevated-dev.com/TechTips/Launchd%20&%20Logging/

shribe commented Apr 13, 2015

Nice example. It helped me figure out what I wanted to do about logging from scripts used with launchd on OS X: http://elevated-dev.com/TechTips/Launchd%20&%20Logging/

@mpdude

This comment has been minimized.

Show comment
Hide comment
@mpdude

mpdude May 11, 2016

Is that for bash only or does it work in sh as well?

mpdude commented May 11, 2016

Is that for bash only or does it work in sh as well?

@spieden

This comment has been minimized.

Show comment
Hide comment
@spieden

spieden Mar 24, 2017

@shribe Thank you! Exactly what I needed.

spieden commented Mar 24, 2017

@shribe Thank you! Exactly what I needed.

@oliver

This comment has been minimized.

Show comment
Hide comment
@oliver

oliver Jun 19, 2018

If you add another "exec " in front of the logger call, you avoid one additional Bash process staying alive all the time (you can see it with pstree). Like this:

exec > >(exec logger -p user.info) 2> >(logger -p user.warn)

@mpdude: the entire concept only works with bash (not with sh), since it uses "Process Substitution" which is a Bash-only feature.

oliver commented Jun 19, 2018

If you add another "exec " in front of the logger call, you avoid one additional Bash process staying alive all the time (you can see it with pstree). Like this:

exec > >(exec logger -p user.info) 2> >(logger -p user.warn)

@mpdude: the entire concept only works with bash (not with sh), since it uses "Process Substitution" which is a Bash-only feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment