Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 2 Jan 2012 14:14:35 -0800
From:      Garrett Cooper <yanegomi@gmail.com>
To:        "Bjoern A. Zeeb" <bzeeb-lists@lists.zabbadoz.net>
Cc:        FreeBSD current mailing list <freebsd-current@freebsd.org>
Subject:   Re: periodic emails
Message-ID:  <CAGH67wSUuzMtS51gOV5POEmuw3Do-Kcg6H3dawpDJ39a=OSw7A@mail.gmail.com>
In-Reply-To: <E4CECE08-C9BE-4CA5-842B-420A44DCF461@lists.zabbadoz.net>
References:  <E4CECE08-C9BE-4CA5-842B-420A44DCF461@lists.zabbadoz.net>

next in thread | previous in thread | raw e-mail | index | archive | help

[-- Attachment #1 --]
On Mon, Jan 2, 2012 at 1:29 PM, Bjoern A. Zeeb
<bzeeb-lists@lists.zabbadoz.net> wrote:
> Hi,
>
> why do we send all these empty headings for periodic emails or given there is
> no output to this one can we
>
> 1) suppress the empty sections (to me that sounds a bit like a wrong
>   return code or something maybe?), and
> 2) add an option to suppress "empty" periodic emails entirely?
>
> Sample:
> -------
> Removing stale files from /var/preserve:
>
> Cleaning out old system announcements:
>
> Removing stale files from /var/rwho:
>
> Backup passwd and group files:
>
> Verifying group file syntax:
> /etc/group is fine
>
> Security check:
>   (output mailed separately)
>
> Checking for denied zone transfers (AXFR and IXFR):
>
> -- End of daily output --
> -------
>
>
> I'd also like to get the hostname out of the headings of the security emails
> if possible.  It's in the Subject:.  There's no need to have each section header
> starting differently.  I understand that it would be a POLA problem given a lot
> of people parse these emails automatically so adding an option for that would be
> ok with me as well.
>
> Any takers?

    How does this look for starters? The attached patch's goal is to
provide a generic, rc(5)-like infrastructure that would quiet down the
periodic emails for 120.clean-preserve .
Thanks,
-Garrett

[-- Attachment #2 --]
Index: etc/periodic.subr
===================================================================
--- etc/periodic.subr	(revision 0)
+++ etc/periodic.subr	(working copy)
@@ -0,0 +1,105 @@
+# $FreeBSD$
+#
+# Copyright (c) 1997-2004 The FreeBSD Foundation, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE FREEBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# periodic.subr
+#	functions used by periodic(5) scripts
+#
+#	Many of the following functions were grabbed wholesale from rc.subr.
+#
+
+#
+# checkyesno var
+#	Test $1 variable, and warn if not set to YES or NO.
+#	Return 0 if it's "yes" (et al), nonzero otherwise.
+#
+checkyesno()
+{
+	eval _value=\$${1}
+	debug "checkyesno: $1 is set to $_value."
+	case $_value in
+
+		#	"yes", "true", "on", or "1"
+	[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1)
+		return 0
+		;;
+
+		#	"no", "false", "off", or "0"
+	[Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0)
+		return 1
+		;;
+	*)
+		warn "\$${1} is not set properly - see ${rcvar_manpage}."
+		return 1
+		;;
+	esac
+}
+
+#
+# debug message
+#	If debugging is enabled in rc.conf output message to stderr.
+#	BEWARE that you don't call any subroutine that itself calls this
+#	function.
+#
+debug()
+{
+	case ${periodic_debug} in
+	[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1)
+		if [ -x /usr/bin/logger ]; then
+			logger "$0: DEBUG: $*"
+		fi
+		echo 1>&2 "$0: DEBUG: $*"
+		;;
+	esac
+}
+
+#
+# err exitval message
+#	Display message to stderr and log to the syslog, and exit with exitval.
+#
+err()
+{
+	exitval=$1
+	shift
+
+	if [ -x /usr/bin/logger ]; then
+		logger "$0: ERROR: $*"
+	fi
+	echo 1>&2 "$0: ERROR: $*"
+	exit $exitval
+}
+
+#
+# warn message
+#	Display message to stderr and log to the syslog.
+#
+warn()
+{
+	if [ -x /usr/bin/logger ]; then
+		logger "$0: WARNING: $*"
+	fi
+	echo 1>&2 "$0: WARNING: $*"
+}
+

Property changes on: etc/periodic.subr
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
Index: etc/periodic/daily/120.clean-preserve
===================================================================
--- etc/periodic/daily/120.clean-preserve	(revision 229316)
+++ etc/periodic/daily/120.clean-preserve	(working copy)
@@ -5,6 +5,8 @@
 # Remove stale files in /var/preserve
 #
 
+. /etc/periodic.subr
+
 # If there is a global system configuration file, suck it in.
 #
 if [ -r /etc/defaults/periodic.conf ]
@@ -13,31 +15,30 @@
     source_periodic_confs
 fi
 
-case "$daily_clean_preserve_enable" in
-    [Yy][Ee][Ss])
+if checkyesno daily_clean_preserve_enable; then
+	rc=0
 	if [ -z "$daily_clean_preserve_days" ]
 	then
-	    echo '$daily_clean_preserve_enable is set but' \
+	    err 2 '$daily_clean_preserve_enable is set but' \
 		'$daily_clean_preserve_days is not'
-	    rc=2
 	elif [ ! -d /var/preserve ]
 	then
-	    echo '$daily_clean_preserve_enable is set but /var/preserve' \
+	    err 2 '$daily_clean_preserve_enable is set but /var/preserve' \
 		"doesn't exist"
-	    rc=2
 	else
-	    echo ""
-	    echo "Removing stale files from /var/preserve:"
 
+	    if checkyesno daily_clean_preserve_verbose; then
+		echo ""
+		echo "Removing stale files from /var/preserve:"
+	    fi
+
 	    if cd /var/preserve
 	    then
-		case "$daily_clean_preserve_verbose" in
-		    [Yy][Ee][Ss])
+		if checkyesno daily_clean_preserve_verbose; then
 			print=-print;;
-		    *)
+		else
 			print=;;
-		esac
-
+		fi
 		rc=$(find . ! -name . -mtime +$daily_clean_preserve_days \
 		    -delete $print | tee /dev/stderr | wc -l)
 		[ -z "$print" ] && rc=0
@@ -45,9 +46,7 @@
 	    else
 		rc=3
 	    fi
-	fi;;
+	fi
+fi
 
-    *)  rc=0;;
-esac
-
 exit $rc

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAGH67wSUuzMtS51gOV5POEmuw3Do-Kcg6H3dawpDJ39a=OSw7A>