xref: /freebsd/usr.sbin/periodic/etc/daily/100.clean-disks (revision cddbc3b40812213ff00041f79174cac0be360a2a)
1#!/bin/sh
2#
3# $FreeBSD$
4#
5# Remove garbage files more than $daily_clean_disks_days days old
6#
7
8# If there is a global system configuration file, suck it in.
9#
10if [ -r /etc/defaults/periodic.conf ]
11then
12    . /etc/defaults/periodic.conf
13    source_periodic_confs
14fi
15
16case "$daily_clean_disks_enable" in
17    [Yy][Ee][Ss])
18	if [ -z "$daily_clean_disks_days" ]
19	then
20	    echo '$daily_clean_disks_enable is set but' \
21		'$daily_clean_disks_days is not'
22	    rc=2
23	elif [ -z "$daily_clean_disks_files" ]
24	then
25	    echo '$daily_clean_disks_enable is set but' \
26		'$daily_clean_disks_files is not'
27	    rc=2
28	else
29	    echo ""
30	    echo "Cleaning disks:"
31	    set -f noglob
32	    args="-name "`echo "$daily_clean_disks_files" |
33		sed -e 's/^[ 	]*//' \
34		    -e 's/[ 	]*$//' \
35		    -e 's/[ 	][ 	]*/ -o -name /g'`
36
37	    case "$daily_clean_disks_verbose" in
38		[Yy][Ee][Ss])
39		    print=-print;;
40		*)
41		    print=;;
42	    esac
43
44	    rc=$(find / \( ! -fstype local -o -fstype rdonly \) -prune -o \
45		\( $args \) -atime +$daily_clean_disks_days \
46		-execdir rm -df {} \; $print | tee /dev/stderr | wc -l)
47	    [ -z "$print" ] && rc=0
48	    [ $rc -gt 1 ] && rc=1
49	    set -f glob
50	fi;;
51
52    *)  rc=0;;
53esac
54
55exit $rc
56