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
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
/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
}
"--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.
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