Use cronic to prevent email logging of gpg key refreshes

This commit is contained in:
Bob Mottram 2016-05-14 12:49:52 +01:00
parent 5582322372
commit 87a6b1935e
2 changed files with 50 additions and 1 deletions

47
src/cronic Normal file
View File

@ -0,0 +1,47 @@
#!/bin/bash
# Cronic v3 - cron job report wrapper
# Copyright 2007-2016 Chuck Houpt. No rights reserved, whatsoever.
# Public Domain CC0: http://creativecommons.org/publicdomain/zero/1.0/
set -eu
TMP=$(mktemp -d)
OUT=$TMP/cronic.out
ERR=$TMP/cronic.err
TRACE=$TMP/cronic.trace
set +e
"$@" >$OUT 2>$TRACE
RESULT=$?
set -e
PATTERN="^${PS4:0:1}\\+${PS4:1}"
if grep -aq "$PATTERN" $TRACE
then
! grep -av "$PATTERN" $TRACE > $ERR
else
ERR=$TRACE
fi
if [ $RESULT -ne 0 -o -s "$ERR" ]
then
echo "Cronic detected failure or error output for the command:"
echo "$@"
echo
echo "RESULT CODE: $RESULT"
echo
echo "ERROR OUTPUT:"
cat "$ERR"
echo
echo "STANDARD OUTPUT:"
cat "$OUT"
if [ $TRACE != $ERR ]
then
echo
echo "TRACE-ERROR OUTPUT:"
cat "$TRACE"
fi
fi
rm -rf "$TMP"

View File

@ -5342,8 +5342,10 @@ function refresh_gpg_keys {
fi
if ! grep -q "$REFRESH_GPG_KEYS_SCRIPT" /etc/crontab; then
GPG_REFRESH_TIME=$(( RANDOM % 60 ))
echo "$GPG_REFRESH_TIME */$REFRESH_GPG_KEYS_HOURS * * * root $REFRESH_GPG_KEYS_SCRIPT 2>&1 > /dev/null" >> /etc/crontab
echo "$GPG_REFRESH_TIME */$REFRESH_GPG_KEYS_HOURS * * * root cronic $REFRESH_GPG_KEYS_SCRIPT 2>&1 > /dev/null" >> /etc/crontab
systemctl restart cron
else
sed -i "s|root $REFRESH_GPG_KEYS_SCRIPT|root cronic $REFRESH_GPG_KEYS_SCRIPT|g" /etc/crontab
fi
}