]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - etc/periodic/daily/110.clean-tmps
Don't try to remove directories unless we've emptied them first
[FreeBSD/FreeBSD.git] / etc / periodic / daily / 110.clean-tmps
1 #!/bin/sh
2 #
3 # $FreeBSD$
4 #
5 # Perform temporary directory cleaning so that long-lived systems
6 # don't end up with excessively old files there.
7 #
8
9 # If there is a global system configuration file, suck it in.
10 #
11 if [ -r /etc/defaults/periodic.conf ]
12 then
13     . /etc/defaults/periodic.conf
14     source_periodic_confs
15 fi
16
17 case "$daily_clean_tmps_enable" in
18     [Yy][Ee][Ss])
19         if [ -z "$daily_clean_tmps_days" ]
20         then
21             echo '$daily_clean_tmps_enable is set but' \
22                 '$daily_clean_tmps_days is not'
23             rc=2
24         else
25             echo ""
26             echo "Removing old temporary files:"
27
28             set -f noglob
29             args="-atime +$daily_clean_tmps_days -mtime +$daily_clean_tmps_days"
30             [ -n "$daily_clean_tmps_ignore" ] &&
31                 args="$args "`echo " ${daily_clean_tmps_ignore% }" |
32                     sed 's/[    ][      ]*/ ! -name /g'`
33             case "$daily_clean_tmps_verbose" in
34                 [Yy][Ee][Ss])
35                     print=-print;;
36                 *)
37                     print=;;
38             esac
39
40             rc=$(for dir in $daily_clean_tmps_dirs
41                 do
42                     [ ."${dir#/}" != ."$dir" -a -d $dir ] && cd $dir && {
43                         find -d . -type f $args -delete $print
44                         find -d . ! -name . -type d -empty -mtime \
45                             +$daily_clean_tmps_days -delete $print
46                     } | sed "s,^\\.,  $dir,"
47                 done | tee /dev/stderr | wc -l)
48             [ -z "$print" ] && rc=0
49             [ $rc -gt 1 ] && rc=1
50             set -f glob
51         fi;;
52
53     *)  rc=0;;
54 esac
55
56 exit $rc