<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