change indent level to 2
[log-quiet] / sysd-mail-once
index 6e6807686a43c3e7f78a6c93b556533da9e8c02a..8feedd377e6324d4d70b5e87f3566495c80fcec9 100755 (executable)
@@ -20,8 +20,8 @@ trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
 errors=3
 cbase=$HOME/sysd-mail-once-state
 case "$1" in
-    -h|--help)
-        cat <<EOF
+  -h|--help)
+    cat <<EOF
 Usage: sysd-log-once [-ERRORS] SERVICE COMMAND [ARGS...]
 For systemd timers, email on repeated failure & success after failure.
 
@@ -34,12 +34,12 @@ Stores error counts in $cbase
 -ERRORS:  ERRORS is the number of failurs to accumulate before mailing the error.
           Default is 3.
 EOF
-        exit 0
-        ;;
-    -[0-9]*)
-        errors=${1#-}
-        shift
-        ;;
+    exit 0
+    ;;
+  -[0-9]*)
+    errors=${1#-}
+    shift
+    ;;
 esac
 service=$1
 shift
@@ -52,29 +52,29 @@ u=${USER:-root}
 [[ -d $cbase ]] || mkdir -p $cbase
 
 if [[ ! $file ]]; then
-    cursor=$(journalctl --show-cursor -qn0|sed 's/^\s*--\scursor:\s*//')
+  cursor=$(journalctl --show-cursor -qn0|sed 's/^\s*--\scursor:\s*//')
 fi
 if "$@"; then
-    if [[ $file ]]; then
-        rm -f $file
-        if [[ $file == $c$errors ]]; then
-            echo | mail -s "$HOSTNAME: $service success" $u@localhost
-        fi
+  if [[ $file ]]; then
+    rm -f $file
+    if [[ $file == $c$errors ]]; then
+      echo | mail -s "$HOSTNAME: $service success" $u@localhost
     fi
+  fi
 else # $@ failed
-    if [[ $file ]]; then
-        i=${file#$c}
-        if (( i < errors )); then
-            new_file=$c$((i+1))
-            mv $file $new_file
-            file=$new_file
-            if [[ $file == $c$errors ]]; then
-                journalctl -u $service.service --after-cursor=$(<$file) | \
-                    mail -s "$HOSTNAME: $service failure" $u@localhost
-            fi
-        fi
-    else
-        file=${c}1
-        printf "%s\n" "$cursor" >$file
+  if [[ $file ]]; then
+    i=${file#$c}
+    if (( i < errors )); then
+      new_file=$c$((i+1))
+      mv $file $new_file
+      file=$new_file
+      if [[ $file == $c$errors ]]; then
+        journalctl -u $service.service --after-cursor=$(<$file) | \
+          mail -s "$HOSTNAME: $service failure" $u@localhost
+      fi
     fi
+  else
+    file=${c}1
+    printf "%s\n" "$cursor" >$file
+  fi
 fi