Skip to content

Instantly share code, notes, and snippets.

@uryossa
Created September 3, 2021 10:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uryossa/ae3ac53ebbc3f0a0b647b3719ae8f26c to your computer and use it in GitHub Desktop.
Save uryossa/ae3ac53ebbc3f0a0b647b3719ae8f26c to your computer and use it in GitHub Desktop.
bash script log to file and stdout
#!/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