2 # Copyright (C) 2019 Ian Kelling
3 # SPDX-License-Identifier: AGPL-3.0-or-later
5 # The panic log regularly gets some stuff in it we dont want to fix.
6 # Detect it and wipe it out.
8 if [ -z "$BASH_VERSION" ]; then echo "error: shell is not bash" >&2; exit 1; fi
10 shopt -s inherit_errexit
2>/dev
/null ||
: # ignore fail in bash < 4.4
12 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
14 [[ $EUID == 0 ]] ||
exec sudo
-E "${BASH_SOURCE[0]}" "$@"
29 if [[ ! -s /var
/log
/exim
4/paniclog
]]; then
33 # seems to randomly be caused by
34 # Starting exim4-base housekeeping, exim4-base.service
35 regex
="^[^ ]* 00:00:0.* Failed writing transport results to pipe: Broken pipe$"
36 grep "$regex" /var
/log
/exim
4/paniclog
>> /var
/log
/exim
4/paniclog-archive ||
:
37 sed -i "/$regex/d" /var
/log
/exim
4/paniclog
39 while read -r service regex
; do
43 while read -r d1 d2
; do
46 tmptime
=$
(date -d "$d1 $d2" +%s
)
47 # dont consider every matching line, just those in > 60 second intervals
48 if [[ ! $logtime ]]; then
50 elif (( tmptime
> logtime
+ 60 )); then
55 sec_min
=$
((logtime
- 60))
56 sec_max
=$
((logtime
+ 60))
57 jmin
="$(date -d @$sec_min "+%F
%H
:%M
:%S
")"
58 jmax
="$(date -d @$sec_max "+%F
%H
:%M
:%S
")"
59 description
=$
(systemctl
cat $service |
sed -rn 's/^ *Description=(.*)/\1/p')
60 jrregex
="^Starting $description"
61 if [[ $service == spamassassin
]]; then
62 jrregex
+="\|^spamd: restarting"
64 d
"jrregex=$jrregex jmin=$jmin jmax=$jmax"
65 # the sed clears out the initial time and process+pid
66 if ! journalctl
-u $service -S "$jmin" -U "$jmax" \
67 |
sed -r 's/^([^[:space:]]*[[:space:]]+){5}//' |
grep "$jrregex" &>/dev
/null
; then
71 done < <(awk "/$regex/ "'{print $1,$2}' /var
/log
/exim
4/paniclog
)
72 if $found && $wipe; then
74 if [[ ! -w /var
/log
/exim
4/paniclog-archive
]]; then
75 touch /var
/log
/exim
4/paniclog-archive
76 chgrp adm
/var
/log
/exim
4/paniclog-archive
77 chmod 664 /var
/log
/exim
4/paniclog-archive
79 grep -E "$regex" /var
/log
/exim
4/paniclog
>> /var
/log
/exim
4/paniclog-archive ||
:
80 sed -ri "/$regex/d" /var
/log
/exim
4/paniclog
83 clamav-daemon malware acl condition
84 spamassassin spam acl condition
88 if [[ $INVOCATION_ID ]]; then
89 # this is to prevent systemd from filling up the journal
90 for (( runcount
=0; runcount
< 100; runcount
++ )); do