Created
October 9, 2019 19:35
-
-
Save fortran01/ddefcc46b02500ec28de17e0ac088585 to your computer and use it in GitHub Desktop.
Log to file and see stdout
This file contains 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
#!/bin/bash | |
logfile="my.log" | |
# Set up a named pipe for logging | |
npipe=/tmp/$$.tmp | |
mknod $npipe p | |
# Log all output to a log for error checking | |
tee <$npipe $logfile & | |
exec 1>&- # close stdout, produces 'write error: Bad file descriptor' if not re-opened below | |
exec 1>$npipe 2>&1 # 2>&1 redirect stderr to stdout | |
trap "rm -f $npipe" EXIT | |
# test | |
ls -al |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Copied from https://raw.githubusercontent.com/DataDog/datadog-agent/master/cmd/agent/install_script.sh