Package: cron-apt Version: 0.11.0 Severity: wishlist Tags: patch Hi,
please consider the attached patch. It makes cron-apt save the mail message sent out in the log dir, allowing processes on the system to access the current last mail message that was generated by cron-apt. This can, for example, be used to output pending updates to a user logging in in their .profile without the delay that comes with actually invoking apt, or to generate a monitoring check warning for pending updates, also without imposing a delay because the information is already there. For example, I do have the followingin my .bash_profile: if [ -r /var/log/cron-apt/lastfullmessage ]; then echo "-------------------" < /var/log/cron-apt/lastfullmessage sed '/^---/,/^-----/d' | grep -vE '^((CRON-APT|To:|Subject:|Reading|Building|Initializing|Writing|Need) .*)?$' echo "-------------------" fi Greetings Marc
>From d0206c644761e7805a74da7641fb1faefd922c05 Mon Sep 17 00:00:00 2001 From: Marc Haber <[email protected]> Date: Wed, 29 Nov 2017 09:21:27 +0100 Subject: [PATCH 3/3] arrange for the last e-mail message sent out to be saved locally. This makes is possible to print it to the console when a user logs in so that she immediately sees that there are pending updates. This could also be used as input for a monitoring plugin --- README | 8 +++++++- src/cron-apt | 4 +++- src/functions | 44 ++++++++++++++++++++++---------------------- 3 files changed, 32 insertions(+), 24 deletions(-) diff --git a/README b/README index e6a5536..60ec0e8 100644 --- a/README +++ b/README @@ -313,8 +313,14 @@ TEMP="/var/log/cron-apt/temp" The temporary file that contains current run information when still running the script. +LOGDIR="/var/log/cron-apt" -LOG="/var/log/cron-apt/log" + The directory to place temporary logs. A convenience copy of the + last mail message sent out is also placed here as + $LOGDIR/lastfullmessage to process in a .profile script or a monitoring + plugin. + +LOG="$LOGDIR/log" The temporary logfile (for debugging). Use syslog for normal logging. diff --git a/src/cron-apt b/src/cron-apt index a3b13cf..d29d39f 100755 --- a/src/cron-apt +++ b/src/cron-apt @@ -227,7 +227,9 @@ NOLOCKWARN="" ERRORMSGDIR="/etc/cron-apt/errormsg.d" SYSLOGMSGDIR="/etc/cron-apt/syslogmsg.d" LOGMSGDIR="/etc/cron-apt/logmsg.d" -LOG="/var/log/cron-apt/log" +LOGDIR="/var/log/cron-apt" +LOG="$LOGDIR/log" +LASTFULLMESSAGE="$LOGDIR/lastfullmessage" DIFFONCHANGES="prepend" SUBJECTPREFIX="CRON-APT" MAILTO="root" diff --git a/src/functions b/src/functions index 234503b..d541517 100644 --- a/src/functions +++ b/src/functions @@ -97,35 +97,35 @@ onexit() { rm -f "$RUNMAIL" fi if [ -f "$MAIL" ] && [ "$MAILON" != "never" ] && [ -n "$MAILON" ] ; then - if command -v sendmail >/dev/null; then - HDR="To: $MAILTO" - if [ -z "$HOSTNAME" ]; then - HOSTNAME="$(uname -n)" - fi - if [ -f "$ERROR" ] ; then - HDR=$(printf "$HDR\nSubject: $SUBJECTPREFIX error on $HOSTNAME [$CONFIG]") - else - HDR=$(printf "$HDR\nSubject: $SUBJECTPREFIX completed on $HOSTNAME [$CONFIG]") - fi - # Support for XHEADERS - i=1 + HDR="To: $MAILTO" + if [ -z "$HOSTNAME" ]; then + HOSTNAME="$(uname -n)" + fi + if [ -f "$ERROR" ] ; then + HDR=$(printf "$HDR\nSubject: $SUBJECTPREFIX error on $HOSTNAME [$CONFIG]") + else + HDR=$(printf "$HDR\nSubject: $SUBJECTPREFIX completed on $HOSTNAME [$CONFIG]") + fi + # Support for XHEADERS + i=1 + eval "VAL=\${XHEADER$i}" + while [ ! -z "$VAL" ] ; do + HDR=$(printf "$HDR\n$VAL") + i=$(( $i + 1 )) eval "VAL=\${XHEADER$i}" - while [ ! -z "$VAL" ] ; do - HDR=$(printf "$HDR\n$VAL") - i=$(( $i + 1 )) - eval "VAL=\${XHEADER$i}" - done - # - ( printf "$HDR\n"; echo; fold --spaces --width=${MAILWIDTH:-900} $MAIL ) | sendmail -t -oi + done + (umask $UMASK_APT && printf "$HDR\n\n" > $LASTFULLMESSAGE) + fold --spaces --width=${MAILWIDTH:-900} $MAIL >> $LASTFULLMESSAGE + # + if command -v sendmail >/dev/null; then + < $LASTFULLMESSAGE sendmail -t -oi else echo >&2 "cron-apt was configured to send e-mail, but no sendmail binary was found in path." echo >&2 "Either set MAILON=never in configuration or install an MTA package." + echo >&2 "The last message generated is saved in $LASTFULLMESSAGE" fi rm -f "$MAIL" fi - if [ -f "$DIFF" ] ; then - rm -f "$DIFF" - fi if [ -d "$TMPDIR" ] ; then rmdir "$TMPDIR" fi -- 2.15.0

