xref: /minix3/etc/usr/daily (revision 69eead77ff7b92014d108017d0765cfa7d3ddba7)
1#!/bin/sh
2#
3# daily - daily cleanup of the system.
4
5# Doesn't make sense when running from CD
6if [ ! -z $(sysenv bootcd) ]
7then	exit
8fi
9
10case "$#:$1" in
111:cron|1:boot)
12    caller=$1
13    ;;
14*)  echo >&2 "Usage: $0 cron|boot"
15    exit 1
16esac
17
18test -d /usr/adm || exit
19cd /usr/adm || exit
20
21# Last run must have been on a previous day.
22timestamp=daily.lasttime
23if test -f $timestamp
24then
25    set -- `ls -lT $timestamp`
26    test "$6 $7 $9" = "$(date '+%b %d %Y')" && exit
27fi
28
29# Update last-run time
30echo >$timestamp
31
32# Remove three day old files from various tmp dirs.
33cleantmp -3 /tmp /usr/tmp /usr/preserve /usr/spool/lpd /usr/spool/at/past
34
35# Truncate log files in /usr/adm.
36test -d old || mkdir old || exit
37
38cycle()
39{
40    # Cycle a log file if larger than a size in kilobytes.
41    local size="`expr "$1" + "$1"`"
42    local log="$2"
43
44    if test -f "$log" && test -n "$(find "$log" -size +"$size")"
45    then
46	test -f "old/$log.2" && cp -p "old/$log.2" "old/$log.3"
47	test -f "old/$log.1" && cp -p "old/$log.1" "old/$log.2"
48	cp -p "$log" "old/$log.1"
49	: > "$log"
50    fi
51}
52
53cycle 100 wtmp
54cycle 100 log
55cycle  20 ftplog
56cycle 200 aftplog
57
58# Make copies of /etc/passwd and /etc/shadow if they have been changed.
59for file in passwd shadow
60do
61    if cmp -s /etc/$file old/$file.1
62    then
63	# Fine.
64    else
65	test -f old/$file.2 && cp -p old/$file.2 old/$file.3
66	test -f old/$file.1 && cp -p old/$file.1 old/$file.2
67	test -f /etc/$file && cp -p /etc/$file old/$file.1
68    fi
69done
70
71# Update manpage index but don't warn about nonexistant dirs
72/usr/libexec/makewhatis -f 2>/dev/null
73
74# Continue with a local script if present.
75test -f /usr/local/etc/daily && sh /usr/local/etc/daily $caller
76exit 0
77