Skip to content

Instantly share code, notes, and snippets.

@gregjhogan
Created January 23, 2019 20:15
Show Gist options
  • Select an option

  • Save gregjhogan/d3630f476f3d14b309c3132c82914808 to your computer and use it in GitHub Desktop.

Select an option

Save gregjhogan/d3630f476f3d14b309c3132c82914808 to your computer and use it in GitHub Desktop.
bash log to file if not running interactively
#!/usr/bin/env bash
set -e
# log to file if not running interactively
if [[ ! -t 1 ]]; then
exec >> >(tee /var/log/$(basename ${0%.*}).log) 2>&1
fi
echo "hello world!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment