110.clean-tmps revision 65843
1284990Scy#!/bin/sh
2284990Scy#
3284990Scy# $FreeBSD: head/etc/periodic/daily/110.clean-tmps 65843 2000-09-14 17:19:15Z brian $
4284990Scy#
5284990Scy# Perform temporary directory cleaning so that long-lived systems
6284990Scy# don't end up with excessively old files there.
7284990Scy#
8284990Scy
9284990Scy# If there is a global system configuration file, suck it in.
10284990Scy#
11284990Scyif [ -r /etc/defaults/periodic.conf ]
12284990Scythen
13284990Scy    . /etc/defaults/periodic.conf
14284990Scy    source_periodic_confs
15284990Scyfi
16284990Scy
17284990Scycase "$daily_clean_tmps_enable" in
18284990Scy    [Yy][Ee][Ss])
19284990Scy	if [ -z "$daily_clean_tmps_days" ]
20284990Scy	then
21284990Scy	    echo '$daily_clean_tmps_enable is set but' \
22284990Scy		'$daily_clean_tmps_days is not'
23284990Scy	    rc=2
24284990Scy	else
25284990Scy	    echo ""
26284990Scy	    echo "Removing old temporary files:"
27284990Scy
28284990Scy	    set -f noglob
29284990Scy	    args="-atime +$daily_clean_tmps_days -mtime +$daily_clean_tmps_days"
30284990Scy	    [ -n "$daily_clean_tmps_ignore" ] &&
31284990Scy		args="$args "`echo " ${daily_clean_tmps_ignore% }" |
32284990Scy		    sed 's/[ 	][ 	]*/ ! -name /g'`
33284990Scy	    case "$daily_clean_tmps_verbose" in
34284990Scy		[Yy][Ee][Ss])
35284990Scy		    print=-print;;
36284990Scy		*)
37284990Scy		    print=;;
38284990Scy	    esac
39284990Scy
40284990Scy	    rc=$(for dir in $daily_clean_tmps_dirs
41284990Scy		do
42284990Scy		    [ ."${dir#/}" != ."$dir" -a -d $dir ] && cd $dir && {
43284990Scy			find -d . -type f $args -delete $print
44284990Scy			find -d . ! -name . -type d -mtime \
45284990Scy			    +$daily_clean_tmps_days -delete $print
46284990Scy		    } | sed "s,^\\.,  $dir,"
47284990Scy		done | tee /dev/stderr | wc -l)
48284990Scy	    [ -z "$print" ] && rc=0
49284990Scy	    [ $rc -gt 1 ] && rc=1
50284990Scy	    set -f glob
51284990Scy	fi;;
52284990Scy
53284990Scy    *)  rc=0;;
54284990Scyesac
55284990Scy
56284990Scyexit $rc
57284990Scy