From hawkeyd@visi.com  Mon Mar  4 12:11:58 2002
Return-Path: <hawkeyd@visi.com>
Received: from breg.mc.mpls.visi.com (breg.mc.mpls.visi.com [208.42.156.101])
	by hub.freebsd.org (Postfix) with ESMTP id A010737B402
	for <FreeBSD-gnats-submit@freebsd.org>; Mon,  4 Mar 2002 12:11:57 -0800 (PST)
Received: from sheol.localdomain (hawkeyd-fw.dsl.visi.com [208.42.101.193])
	by breg.mc.mpls.visi.com (Postfix) with ESMTP
	id 4B3272D049B; Mon,  4 Mar 2002 14:11:56 -0600 (CST)
Received: (from hawkeyd@localhost)
	by sheol.localdomain (8.11.6/8.11.6) id g24KBsv55481;
	Mon, 4 Mar 2002 14:11:54 -0600 (CST)
	(envelope-from hawkeyd)
Message-Id: <200203042011.g24KBsv55481@sheol.localdomain>
Date: Mon, 4 Mar 2002 14:11:54 -0600 (CST)
From: D J Hawkey Jr <hawkeyd@visi.com>
Reply-To: D J Hawkey Jr <hawkeyd@visi.com>
To: FreeBSD-gnats-submit@freebsd.org
Subject: Enhanced periodic scripts
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         35545
>Category:       conf
>Synopsis:       [periodic] [patch] enhanced periodic scripts: 100.clean-disks, 100.clean-tmps
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Mar 04 12:20:01 PST 2002
>Closed-Date:    
>Last-Modified:  Sun Feb 20 05:12:14 UTC 2011
>Originator:     David J Hawkey Jr \<hawkeyd@visi.com\>
>Release:        FreeBSD 4.5-RELEASE i386
>Organization:
if (!FIFO) if (!LIFO) break;
>Environment:
System: FreeBSD sheol.localdomain 4.5-RELEASE FreeBSD 4.5-RELEASE #2: Mon Feb 11 09:18:49 CST 2002 root@sheol.localdomain:/usr/src/sys/compile/SHEOL i386


>Description:

/etc/periodic/daily/100.clean-disks should have "exclude paths".
/etc/periodic/daily/110.clean-tmps removes empty directories, and should
not, IMHO.

>How-To-Repeat:

Enable either in /etc/periodic.conf

>Fix:

These two patches. The first, for 100.clean-disks, honors a new variable,
daily_clean_disks_excludes (ex., "*/home/*"). The second, for 110.clean-tmps,
honors a new variable, daily_clean_tmps_prune (ex., "YES" or "NO").
Additionally, they both actually make their *_verbose variables do the
Right Thing(tm), and could pro'lly be applied to many more of the periodic
scripts.

They both should be scrutinized for correctness. They test out fine here,
and fulfill my needs, but may not be generic enough, and I may be blind to
some nuances of 'find' and/or 'periodic'.

--- 100.clean-disks.orig	Mon Jan 28 07:13:17 2002
+++ 100.clean-disks	Mon Mar  4 13:18:35 2002
@@ -33,6 +33,12 @@
 		sed -e 's/^[ 	]*//' \
 		    -e 's/[ 	]*$//' \
 		    -e 's/[ 	][ 	]*/ -o -name /g'`
+	    [ -n "$daily_clean_disks_excludes" ] &&
+		excl="$excl ! -path "`echo "$daily_clean_disks_excludes" |
+		    sed -e 's/^[ 	]*//' \
+			-e 's/[ 	]*$//' \
+			-e 's/[ 	][ 	]*/ -a ! -path /g'` &&
+		    excl="( $excl ) -a"
 
 	    case "$daily_clean_disks_verbose" in
 		[Yy][Ee][Ss])
@@ -41,9 +47,21 @@
 		    print=;;
 	    esac
 
+	    # $print is currently meaningless, but retained for if
+	    # and when 'find' without "-print" actually inhibits output.
+	    # $out is a hack until then.
+
+	    out=/var/run/_100_clean-disks_out.$$
 	    rc=$(find / \( ! -fstype local -o -fstype rdonly \) -a -prune -o \
-		\( $args \) -atime +$daily_clean_disks_days -delete $print |
-		tee /dev/stderr | wc -l)
+		$excl \( $args \) -atime +$daily_clean_disks_days \
+		-delete $print | tee $out | wc -l)
+	    if [ -n "$print" ]
+	    then
+		cat $out
+	    else
+		echo "  (output inhibited)"
+	    fi
+	    rm -f $out
 	    [ -z "$print" ] && rc=0
 	    [ $rc -gt 1 ] && rc=1
 	    set -f glob


--- 110.clean-tmps.orig	Mon Jan 28 07:13:17 2002
+++ 110.clean-tmps	Mon Mar  4 12:00:53 2002
@@ -36,15 +36,40 @@
 		*)
 		    print=;;
 	    esac
+	    case "$daily_clean_tmps_prune" in
+		[Yy][Ee][Ss])
+		    delete=-delete;;
+		*)
+		    delete=;;
+	    esac
 
+	    # $print is currently meaningless, but retained for if
+	    # and when 'find' without "-print" actually inhibits output.
+	    # $out is a hack until then.
+
+	    out=/var/run/_110_clean_tmps_out.$$
+	    tmp=/var/run/_110_clean_tmps_tmp.$$
 	    rc=$(for dir in $daily_clean_tmps_dirs
 		do
 		    [ ."${dir#/}" != ."$dir" -a -d $dir ] && cd $dir && {
 			find -d . -type f $args -delete $print
 			find -d . ! -name . -type d -empty -mtime \
-			    +$daily_clean_tmps_days -delete $print
+			    +$daily_clean_tmps_days $delete $print > $tmp
+			if [ -s $tmp ]; then
+			    echo -n "  Empty directories"
+			    [ -n "$delete" ] && echo -n " removed"
+			    echo ":"
+			    sed "s,^\\.,    $dir," $tmp
+			fi
 		    } | sed "s,^\\.,  $dir,"
-		done | tee /dev/stderr | wc -l)
+		done | tee $out | wc -l)
+	    if [ -n "$print" ]
+	    then
+		cat $out
+	    else
+		echo "  (output inhibited)"
+	    fi
+	    rm -f $out $tmp
 	    [ -z "$print" ] && rc=0
 	    [ $rc -gt 1 ] && rc=1
 	    set -f glob


>Release-Note:
>Audit-Trail:

From: chukharev@mail.ru
To: bug-followup@freebsd.org, hawkeyd@visi.com
Cc:  
Subject: Re: conf/35545: [patch] enhanced periodic scripts: 100.clean-disks,
 100.clean-tmps
Date: Sun, 14 Mar 2010 16:24:03 +0200

 A similar patch is in a closed PR conf/129697 .
 
 A related PR conf/84752 refers to this one.
 
 -- 
 Vladimir Chukharev
 Tampere University of Technology
>Unformatted:
