case $1 in
-h|--help)
cat <<'EOF'
-usage: logmail CMD [ARGS...]
+usage: failmail CMD [ARGS...]
Send mail in case of failure of CMD
+
+Emails to $MAILTO or if unset, $USER@localhost
EOF
exit 0
;;
esac
+mailto=$USER@localhost
+if [[ $MAILTO ]]; then
+ mailto=$MAILTO
+fi
+
t=$(mktemp)
if ! "$@" &>"$t"; then
- mail -s "$HOSTNAME: $*" $USER@localhost <"$t"
+ mail -s "$HOSTNAME: $*" $mailto <"$t"
rm "$t"
fi
exit 0
usage: logmail CMD [ARGS...]
Send mail in case of output or failure of CMD
+
+Emails to $MAILTO or if unset, $USER@localhost
EOF
exit 0
;;
esac
t=$(mktemp)
if ! "$@" &>"$t" || [[ ! -s $t ]]; then
- mail -s "$HOSTNAME: $*" $USER@localhost <"$t"
+ mail -s "$HOSTNAME: $*" $mailto <"$t"
rm "$t"
fi
exit 0
fi
else
if $dry; then
- echo "setup dry run: install -v ${files[*]} /usr/local/bin"
+ echo "setup dry run: install ${files[*]} /usr/local/bin"
else
- install -v ${files[@]} /usr/local/bin
+ install ${files[@]} /usr/local/bin
fi
fi
service=$1
shift
-c=$cbase/$service
+c=$cbase/$service # c for command file path base
glob="$c[0-9]*"
arr=($glob); file="${arr[0]}"; [[ $glob != "$file" ]] || file=
else
file=${c}1
printf "%s\n" "$cursor" >$file
+ if (( errors == 1 )); then
+ journalctl -u $service.service --after-cursor=$(<$file) | \
+ mail -s "$HOSTNAME: $service failure" $u@localhost
+ fi
fi
fi