Skip to content

Instantly share code, notes, and snippets.

@thomasfaingnaert
Created July 5, 2019 09:19
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 thomasfaingnaert/574d9cb20aa9cae3c996c0c9e56dda05 to your computer and use it in GitHub Desktop.
Save thomasfaingnaert/574d9cb20aa9cae3c996c0c9e56dda05 to your computer and use it in GitHub Desktop.
Wrap executable and write stdout and stderr to file

Without timestamps:

#!/usr/bin/env bash

exec > >(tee -ai ~/app-stdout.log) 2> >(tee -ai ~/app-stderr.log >&2)
app $*

With timestamps (requires ts from moreutils):

#!/usr/bin/env bash

exec > >(tee >(ts '[%Y-%m-%d %H:%M:%S]' >>~/app-stdout.log)) \
    2> >(tee >(ts '[%Y-%m-%d %H:%M:%S]' >>~/app-stderr.log) >&2)
app $*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment