Last active
November 4, 2025 15:02
-
-
Save reduardo7/5d8443130495d3ad0e630eb344a37707 to your computer and use it in GitHub Desktop.
Output prefix with timestamp
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 | |
| { | |
| echo foo 1 | |
| sleep 1 | |
| echo bar 1 >&2 | |
| echo foo 2 | |
| sleep 1 | |
| echo bar 2 >&2 | |
| } \ | |
| 2> >(perl -pe 'use POSIX strftime; print strftime("%Y-%m-%d %H:%M:%S", localtime) . " [ERR] "' >&2) \ | |
| > >(perl -pe 'use POSIX strftime; print strftime("%Y-%m-%d %H:%M:%S", localtime) . " [INF] "') |
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 | |
| # Time | |
| output-prefix() { | |
| "$@" \ | |
| 2> >(perl -pe 'use POSIX strftime; print strftime("%Y-%m-%d %H:%M:%S", localtime) . " [ERR]'"${prefix}"' "' >&2) \ | |
| > >(perl -pe 'use POSIX strftime; print strftime("%Y-%m-%d %H:%M:%S", localtime) . " [INF]'"${prefix}"' "') | |
| } | |
| output-prefix ./loop.sh foo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ha sorry must've mixed up my tests, seems ok!