#!/bin/bash # Copyright (C) 2019 Ian Kelling # SPDX-License-Identifier: AGPL-3.0-or-later # The panic log regularly gets some stuff in it we dont want to fix. # Detect it and wipe it out. if [ -z "$BASH_VERSION" ]; then echo "error: shell is not bash" >&2; exit 1; fi shopt -s inherit_errexit 2>/dev/null ||: # ignore fail in bash < 4.4 set -eE -o pipefail trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR [[ $EUID == 0 ]] || exec sudo -E "${BASH_SOURCE[0]}" "$@" if [[ ! -s /var/log/exim4/paniclog ]]; then exit 0 fi wipe=false while read -r d1 d2; do tmptime=$(date -d "$d1 $d2" +%s) # dont consider every matching line, just those in > 60 second intervals if [[ ! $logtime ]]; then logtime=$tmptime elif (( tmptime > logtime + 60 )); then logtime=$tmptime else continue fi sec_min=$((logtime - 60)) sec_max=$((logtime + 60)) jmin="$(date -d @$sec_min "+%F %H:%M:%S")" jmax="$(date -d @$sec_max "+%F %H:%M:%S")" if journalctl -S "$jmin" -U "$jmax" \ | awk '$6 == "spamd:" && $7 == "restarting"' | grep . &>/dev/null; then wipe=true break fi done < <(awk '/spam acl condition/ {print $1,$2}' /var/log/exim4/paniclog) if $wipe; then regex="^$(date -d @$logtime "+%F %H:%M" )|^${jmin%:*}|^${jmax%:*}" grep -E "$regex" /var/log/exim4/paniclog >> /var/log/exim4/paniclog-archive sed -ri "/$regex/d" /var/log/exim4/paniclog fi