Skip to content

Instantly share code, notes, and snippets.

@trepmal
Last active May 11, 2017 20:32
Show Gist options
  • Save trepmal/7e56d9f6e359c288005ccb037a935df1 to your computer and use it in GitHub Desktop.
Save trepmal/7e56d9f6e359c288005ccb037a935df1 to your computer and use it in GitHub Desktop.
<some-command> | tee some.log ; \
  ( [[ ${PIPESTATUS[0]} -eq 1 ]] \
  && (tail some.log | mail -s '<some-command> exited with error' [email protected]) \
  || (tail some.log | mail -s '<some-command> finished' [email protected]) )

breakdown:

<some-command> | tee some.log;
run command, tee output to log (display in terminal, and writes to file)

(
group this stuff

[[ ${PIPESTATUS[0]} -eq 1 ]]
check exit code of <some-command>. this is bash specific.

&& (tail some.log | mail -s '<some-command> exited with error' [email protected])
on success, email tail of log

|| (tail some.log | mail -s '<some-command> finished' [email protected])
else, on fail also email tail of log

)
close

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment