<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:
| tee some.log;