Skip to content

Instantly share code, notes, and snippets.

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 motionbug/29cf7edff9a9ba51724dc6079f74fbfa to your computer and use it in GitHub Desktop.
Save motionbug/29cf7edff9a9ba51724dc6079f74fbfa to your computer and use it in GitHub Desktop.
tee stdout to log inside bash script
#! /bin/bash
# concept from http://stackoverflow.com/a/3403786/267224
#############
# log to file
LOGFILE=/home/user/log/script.log
exec > >(tee -a $LOGFILE)
exec 2>&1
############
# anything that outputs to stdout or stderr...
# don't need to pipe or tee the script itself, just run it and it pipes internally.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment