summaryrefslogtreecommitdiff
path: root/etc/usr/daily
blob: 21e45c2ba52edfe551b45ee7e4908511a49469bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/sh
#
# daily - daily cleanup of the system.

# Doesn't make sense when running from CD
if [ ! -z $(sysenv bootcd) ]
then	exit
fi

case "$#:$1" in
1:cron|1:boot)
    caller=$1
    ;;
*)  echo >&2 "Usage: $0 cron|boot"
    exit 1
esac

test -d /usr/adm || exit
cd /usr/adm || exit

# Last run must have been on a previous day.
timestamp=daily.lasttime
if test -f $timestamp
then
    set -- `ls -lT $timestamp`
    test "$6 $7 $9" = "$(date '+%b %d %Y')" && exit
fi

# Update last-run time
echo >$timestamp

# Remove three day old files from various tmp dirs.
cleantmp -3 /tmp /usr/tmp /usr/preserve /usr/spool/lpd /usr/spool/at/past

# Truncate log files in /usr/adm.
test -d old || mkdir old || exit

cycle()
{
    # Cycle a log file if larger than a size in kilobytes.
    local size="`expr "$1" + "$1"`"
    local log="$2"

    if test -f "$log" && test -n "$(find "$log" -size +"$size")"
    then
	test -f "old/$log.2" && cp -p "old/$log.2" "old/$log.3"
	test -f "old/$log.1" && cp -p "old/$log.1" "old/$log.2"
	cp -p "$log" "old/$log.1"
	: > "$log"
    fi
}

cycle 100 wtmp
cycle 100 log
cycle  20 ftplog
cycle 200 aftplog

# Make copies of /etc/passwd and /etc/shadow if they have been changed.
for file in passwd shadow
do
    if cmp -s /etc/$file old/$file.1
    then
	# Fine.
    else
	test -f old/$file.2 && cp -p old/$file.2 old/$file.3
	test -f old/$file.1 && cp -p old/$file.1 old/$file.2
	test -f /etc/$file && cp -p /etc/$file old/$file.1
    fi
done

# Update manpage index but don't warn about nonexistant dirs
/usr/libexec/makewhatis -f 2>/dev/null

# Continue with a local script if present.
test -f /usr/local/etc/daily && sh /usr/local/etc/daily $caller
exit 0