From: Dustin Kirkland Date: Mon, 10 Nov 2008 23:24:25 +0000 (+0100) Subject: Added support to update-motd to allow for message modules to run with X-Git-Url: http://git.etc.gen.nz/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0dc5469cbc9ff827c618a341ac1d6116b3a66a05;p=update-motd.git Added support to update-motd to allow for message modules to run with frequencies other than every 10 minutes (hourly, daily, weekly, monthly) --- diff --git a/update-motd b/update-motd index 044802c..31a34fb 100755 --- a/update-motd +++ b/update-motd @@ -32,6 +32,7 @@ NEW=/var/run/motd.new SKEL=/etc/motd.tail REAL=/var/run/motd DIR=/etc/$NAME.d +FREQ= DISABLED=/var/lib/$NAME/disabled LASTRUN=/var/run/$NAME.lastrun FORCE=0 @@ -45,7 +46,7 @@ fi usage() { echo "Usage: - update-motd [--disable|--enable|--force] + update-motd [--disable|--enable|--force] [d|hourly|daily|weekly|monthly] --disable - will prevent update-motd from running; useful for temporarily disabling automatic updates of /etc/motd @@ -55,6 +56,11 @@ usage() { /etc/cron.d/update-motd cronjob. --force - will override a disabled update-motd for a single update of /etc/motd. + d - will run the scripts in /etc/$NAME.d (Default) + hourly - will run the scripts in /etc/$NAME.d/hourly + daily - will run the scripts in /etc/$NAME.d/daily + weekly - will run the scripts in /etc/$NAME.d/weekly + monthly - will run the scripts in /etc/$NAME.d/monthly " 1>&2 } @@ -79,12 +85,19 @@ for arg in $@; do "--force"|"-f") FORCE=1 ;; + "d") + FREQ= + ;; + "hourly"|"daily"|"weekly"|"monthly") + FREQ=$arg + ;; *) usage exit 1 ;; esac done +DIR="$DIR/$FREQ" if [ -f "$DISABLED" ] && [ "$FORCE" != "1" ]; then echo "$NAME is currently disabled. @@ -103,8 +116,22 @@ trap "rm -f $NEW 2>/dev/null || true" EXIT HUP INT QUIT TERM uname -snrvm > $NEW [ -f $SKEL ] && cat $SKEL >> $NEW -# Run each script, appending to the new motd -run-parts --lsbsysinit $DIR >>$NEW 2>/dev/null +# Create a directory to cache the script output across update-motd +# runs of different frequencies +mkdir -p "/var/run/$NAME" +# Obtain a list of the current scripts "due" to run +scripts=`run-parts --lsbsysinit --test $DIR` +for script in $scripts; do + file=`basename "$script"` + # Run each script, writing to a cache file, of the same num-name + # of the script executing + $script > "/var/run/$NAME/$file" 2>/dev/null +done +# Now, concatenate ALL of the cached update-motd output, thus collecting +# ordered output across update-motd runs of different frequencies +for file in `ls /var/run/$NAME`; do + cat "/var/run/$NAME/$file" >> $NEW +done # Move the new motd into place mv -f $NEW $REAL