From: Ian Kelling Date: Mon, 14 Jun 2021 18:11:06 +0000 (-0400) Subject: fix sysd-mail-once missing email on 1 error, minor improvements X-Git-Url: https://iankelling.org/git/?a=commitdiff_plain;h=7f7ce3ccf4269622c5e40556ef8b3b1e9b07ab47;p=log-quiet fix sysd-mail-once missing email on 1 error, minor improvements --- diff --git a/failmail b/failmail index 377564e..6360c7e 100755 --- a/failmail +++ b/failmail @@ -16,17 +16,24 @@ 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 diff --git a/logmail b/logmail index 4aad395..00b6b0a 100755 --- a/logmail +++ b/logmail @@ -19,13 +19,15 @@ case $1 in 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 diff --git a/setup b/setup index 7ce3624..5897f56 100755 --- a/setup +++ b/setup @@ -65,8 +65,8 @@ if $uninstall; then 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 diff --git a/sysd-mail-once b/sysd-mail-once index 8feedd3..e53d6ee 100755 --- a/sysd-mail-once +++ b/sysd-mail-once @@ -44,7 +44,7 @@ esac 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= @@ -76,5 +76,9 @@ else # $@ failed 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