Skip to content

Instantly share code, notes, and snippets.

@originalsouth
Last active May 16, 2017 11:56
Show Gist options
  • Save originalsouth/8a225aaa412140b8b4992f5a46eede93 to your computer and use it in GitHub Desktop.
Save originalsouth/8a225aaa412140b8b4992f5a46eede93 to your computer and use it in GitHub Desktop.
"mailman send an email to ... when program this program/simulation is done"
#!/usr/bin/env zsh
TO=root@localhost #EMAIL address of the recipient
HOST=127.0.0.1 #HOSTNAME with SSMTP service
main()
{
START=$(date +%s)
STARTT="$(date)"
OUT="$(mktemp mm.XXXXXXXXXX)"
echo "##[mm]: launched in folder $(pwd) with pid $$" > $OUT
echo "##[mm] received output:" >> $OUT
if [ "$1" = "-" ]
then
cat - &>> $OUT
else
$@ &>> $OUT
fi
SUB="[mm]: '$@' by $(whoami)@$(hostname) at $STARTT"
SEDEXP='1i ##[mm]: "'$@'" ran for '$(($(date +%s)-$START))'s'
sed -i "$SEDEXP" $OUT
tail --bytes 1000000 $OUT | ssh $HOST "mail -s \"$SUB\" $TO"
rm -f $OUT
}
if [ $# -eq 0 ]
then
echo "mm: to what do I owe the extreme pleasure of this visit?"
else
main "$@" &
disown
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment