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