source: trunk/minix/etc/usr/daily@ 15

Last change on this file since 15 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 1.5 KB
Line 
1#!/bin/sh
2#
3# daily - daily cleanup of the system.
4
5# Doesn't make sense when running from CD
6if [ -f /CD ]
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>$timestamp
29
30# Remove three day old files from various tmp dirs.
31cleantmp -3 /tmp /usr/tmp /usr/preserve /usr/spool/lpd /usr/spool/at/past
32
33# Truncate log files in /usr/adm.
34test -d old || mkdir old || exit
35
36cycle()
37{
38 # Cycle a log file if larger than a size in kilobytes.
39 local size="`expr "$1" + "$1"`"
40 local log="$2"
41
42 if test -f "$log" && test -n "$(find "$log" -size +"$size")"
43 then
44 test -f "old/$log.2" && cp -p "old/$log.2" "old/$log.3"
45 test -f "old/$log.1" && cp -p "old/$log.1" "old/$log.2"
46 cp -p "$log" "old/$log.1"
47 : > "$log"
48 fi
49}
50
51cycle 100 wtmp
52cycle 100 log
53cycle 20 ftplog
54cycle 200 aftplog
55
56# Make copies of /etc/passwd and /etc/shadow if they have been changed.
57for file in passwd shadow
58do
59 if cmp -s /etc/$file old/$file.1
60 then
61 # Fine.
62 else
63 test -f old/$file.2 && cp -p old/$file.2 old/$file.3
64 test -f old/$file.1 && cp -p old/$file.1 old/$file.2
65 test -f /etc/$file && cp -p /etc/$file old/$file.1
66 fi
67done
68
69# Continue with a local script if present.
70test -f /usr/local/etc/daily && sh /usr/local/etc/daily $caller
71exit 0
Note: See TracBrowser for help on using the repository browser.