- grep "$regex" /var/log/exim4/paniclog >> /var/log/exim4/paniclog-archive ||:
- sed -i "/$regex/d" /var/log/exim4/paniclog
+ grep "$regex" $pl >> $pl-archive ||:
+ sed -i "/$regex/d" $pl
+
+ ## begin broken pipe ##
+ regex="Failed writing transport results to pipe: Broken pipe$"
+ now_s=$(date +%s)
+ newlines=false
+ count=0
+ while read -r day time _; do
+ log_s=$(date -d "$day $time" +%s)
+ count=$((count+1))
+ if (( now_s - 300 > log_s )); then
+ newlines=true
+ fi
+ done < <(grep "$regex" $pl ||:)
+ if (( count )); then
+ # i see these in groups of 3 for the same message around once a day
+ # randomly. I'm guessing they are related to running 2 instances of
+ # exim which share the same spool. So, if we have some, but not in
+ # the last 5 minutes, and less than 20, it should be fine to clear
+ # them.
+ if (( count > 20 )); then
+ cat $pl
+ elif ! $newlines; then
+ grep "$regex" $pl >>$pl-archive
+ sed -i "/$regex/d" $pl
+ fi
+ fi
+ ## end broken pipe ##