From 87a6b1935e52fbb48891a51c0a6fca7a17ef76dd Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 14 May 2016 12:49:52 +0100 Subject: [PATCH] Use cronic to prevent email logging of gpg key refreshes --- src/cronic | 47 +++++++++++++++++++++++++++++++++++++++++++++++ src/freedombone | 4 +++- 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 src/cronic diff --git a/src/cronic b/src/cronic new file mode 100644 index 00000000..b8404792 --- /dev/null +++ b/src/cronic @@ -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" diff --git a/src/freedombone b/src/freedombone index ff7895f4..4dad276c 100755 --- a/src/freedombone +++ b/src/freedombone @@ -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 }