iankelling.org
/
git
/
log-quiet
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
stop returning 1. use pipefail if needed
[log-quiet]
/
sysd-mail-once
diff --git
a/sysd-mail-once
b/sysd-mail-once
index ccaee0a35de46ed9b33f7fde7bb329cad8e5d1d7..6e6807686a43c3e7f78a6c93b556533da9e8c02a 100755
(executable)
--- a/
sysd-mail-once
+++ b/
sysd-mail-once
@@
-18,17
+18,21
@@
set -eE -o pipefail
trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
errors=3
trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
errors=3
-cbase=
/var/local/cron-errors
+cbase=
$HOME/sysd-mail-once-state
case "$1" in
-h|--help)
cat <<EOF
case "$1" in
-h|--help)
cat <<EOF
-Usage: sysd-log-once [-ERRORS] SERVICE COMMAND
+Usage: sysd-log-once [-ERRORS] SERVICE COMMAND [ARGS...]
+For systemd timers, email on repeated failure & success after failure.
-Use to wrap systemd timers and to email on repeated failure & success after failure
+In the service triggered by the timer, prepend this script to the ExecStart.
+The email will contain the service's logs for the last ERRORS runs.
-Stores error counts in $c\$error_count
--ERRORS: ERRORS is the number of failurs to accumulate before mailing the error
+Stores error counts in $cbase
+
+-ERRORS: ERRORS is the number of failurs to accumulate before mailing the error.
+ Default is 3.
EOF
exit 0
;;
EOF
exit 0
;;
@@
-47,7
+51,9
@@
arr=($glob); file="${arr[0]}"; [[ $glob != "$file" ]] || file=
u=${USER:-root}
[[ -d $cbase ]] || mkdir -p $cbase
u=${USER:-root}
[[ -d $cbase ]] || mkdir -p $cbase
-cursor=$(journalctl --show-cursor -qn0|sed 's/^\s*--\scursor:\s*//')
+if [[ ! $file ]]; then
+ cursor=$(journalctl --show-cursor -qn0|sed 's/^\s*--\scursor:\s*//')
+fi
if "$@"; then
if [[ $file ]]; then
rm -f $file
if "$@"; then
if [[ $file ]]; then
rm -f $file
@@
-55,7
+61,7
@@
if "$@"; then
echo | mail -s "$HOSTNAME: $service success" $u@localhost
fi
fi
echo | mail -s "$HOSTNAME: $service success" $u@localhost
fi
fi
-else
+else
# $@ failed
if [[ $file ]]; then
i=${file#$c}
if (( i < errors )); then
if [[ $file ]]; then
i=${file#$c}
if (( i < errors )); then
@@
-63,12
+69,12
@@
else
mv $file $new_file
file=$new_file
if [[ $file == $c$errors ]]; then
mv $file $new_file
file=$new_file
if [[ $file == $c$errors ]]; then
- journalctl -u $service.service --after-cursor=$
cursor
| \
+ journalctl -u $service.service --after-cursor=$
(<$file)
| \
mail -s "$HOSTNAME: $service failure" $u@localhost
fi
fi
else
file=${c}1
mail -s "$HOSTNAME: $service failure" $u@localhost
fi
fi
else
file=${c}1
-
touch
$file
+
printf "%s\n" "$cursor" >
$file
fi
fi
fi
fi