X-Git-Url: https://iankelling.org/git/?p=log-quiet;a=blobdiff_plain;f=sysd-mail-once;fp=sysd-mail-once;h=c5cd8c84670c257448e19e6ec9b73b58f6a1c8f3;hp=32aa02d2dbd5911c72656b1b5f39595acfc7c1d6;hb=bc712f26afdccd6ecea609edc3705ae719c55b8d;hpb=28063c969e568f0342cb5de4d883e391428b299d diff --git a/sysd-mail-once b/sysd-mail-once index 32aa02d..c5cd8c8 100755 --- a/sysd-mail-once +++ b/sysd-mail-once @@ -22,6 +22,7 @@ tmp=(~) cbase="${tmp[0]}/sysd-mail-once-state" to=root dryrun=false +print_all=false while [[ $1 == -* ]]; do case "$1" in -h|--help) @@ -40,6 +41,7 @@ Stores error counts in $cbase -ERRORS ERRORS is the number of failurs to accumulate before mailing the error. Default is 3. +-a Email the logs of all errors intead of just the last one. -t TO_ADDRESS Address to email about errors -n Dry run. Execute command but only print out what we would do in response. EOF @@ -48,6 +50,9 @@ EOF -[0-9]*) errors=${1#-} ;; + -a) + print_all=true + ;; -t) to="$2" shift @@ -110,14 +115,12 @@ if ! [[ -d $cbase ]]; then mkdir -p $cbase fi -if [[ ! $file ]]; then - cursor=$(journalctl --show-cursor -qn0|sed 's/^\s*--\scursor:\s*//') -fi code=0 "$@" || code=$? if (( code )); then send_mail=false + cursor=$(journalctl --show-cursor -qn0|sed 's/^\s*--\scursor:\s*//') if [[ $file ]]; then i=${file#"$c"} if (( i < errors )); then @@ -126,6 +129,12 @@ if (( code )); then file=$new_file if [[ $file == $c$errors ]]; then send_mail=true + else + if $dryrun; then + printf "dryrun: appending to file $file: %s\n" "$cursor" + else + printf "%s\n" "$cursor" >>$file + fi fi fi else @@ -140,13 +149,18 @@ if (( code )); then fi fi if $send_mail; then + if $print_all; then + cursor=$(head -n1 $file) + else + cursor=$(tail -n1 $file) + fi echo "sysd-mail-once: emailing on $errors errors. exit code: $code" mi exim -odf -t <