Skip to content

Instantly share code, notes, and snippets.

@nuada
Created November 26, 2015 11:15
Show Gist options
  • Save nuada/e3b6278df68c8d081d59 to your computer and use it in GitHub Desktop.
Save nuada/e3b6278df68c8d081d59 to your computer and use it in GitHub Desktop.
BASH script that automatically logs strerr and stdout to given file.
#!/bin/bash
LOG=/path/to/log_file.log
>${LOG}
exec > >(tee -a ${LOG})
trap "kill -9 $! 2>/dev/null" EXIT
exec 2> >(tee -a ${LOG} >&2)
trap "kill -9 $! 2>/dev/null" EXIT
echo Test 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment