Created
September 3, 2021 10:17
-
-
Save uryossa/ae3ac53ebbc3f0a0b647b3719ae8f26c to your computer and use it in GitHub Desktop.
bash script log to file and stdout
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
#!/bin/bash | |
LOGFILE=/path/to/logfile | |
{ | |
command 1 | |
command 2 | |
} 2>&1 | tee >(awk '{print strftime("%Y/%m/%d %H:%M:%S "),$0 } { fflush() }' >>$LOGFILE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment