3 # $NetBSD: daily,v 1.71 2008/08/30 10:53:22 bouyer Exp $
4 # @(#)daily 8.2 (Berkeley) 1/25/94
7 export PATH
=/bin
:/usr
/bin
:/sbin
:/usr
/sbin
10 if [ -s /etc
/daily.conf
]; then
16 rcvar_manpage
='daily.conf(5)'
18 echo "To: ${MAILTO:-root}"
19 echo "Subject: $host daily output for $date"
22 if [ -f /etc
/rc.subr
]; then
25 echo "Can't read /etc/rc.subr; aborting."
29 if [ -z "$MAILTO" -o "$USER" != "root" ]; then
34 echo "Uptime: " `uptime`
36 # Uncommenting any of the finds below would open up a race condition attack
37 # based on symlinks, potentially allowing removal of any file on the system.
40 #echo "Removing scratch and junk files:"
41 #if [ -d /tmp -a ! -h /tmp ]; then
43 # find . -type f -atime +3 -exec rm -f -- {} \;
44 # find . ! -name . -type d -mtime +1 -exec rmdir -- {} \; \
48 #if [ -d /var/tmp -a ! -h /var/tmp ]; then
50 # find . ! -name . -atime +7 -exec rm -f -- {} \;
51 # find . ! \( -name . -o -name vi.recover \) -type d \
52 # -mtime +1 -exec rmdir -- {} \; \
56 # Additional junk directory cleanup would go like this:
57 #if [ -d /scratch -a ! -h /scratch ]; then
59 # find . ! -name . -atime +1 -exec rm -f -- {} \;
60 # find . ! -name . -type d -mtime +1 -exec rmdir -- {} \; \
64 #if [ -d /var/rwho -a ! -h /var/rwho ] ; then
66 # find . ! -name . -mtime +7 -exec rm -f -- {} \; ; }
69 DAILYDIR
=$
(mktemp
-d -t _daily
) ||
exit 1
71 trap "/bin/rm -rf $DAILYDIR ; exit 0" EXIT INT QUIT
73 if ! cd "$DAILYDIR"; then
74 echo "Can not cd to $DAILYDIR".
81 if checkyesno find_core
; then
82 # Turn "foo !bar bax" into "-fstype foo -o ! -fstype bar -o -fstype bax"
83 ignfstypes
=`echo $find_core_ignore_fstypes | \
84 sed -e's/\(!*\)\([^[:space:]]\{1,\}\)/-o \1 -fstype \2/g' \
86 find / \
( $ignfstypes \
) -prune -o \
87 -name 'lost+found' -prune -o \
88 \
( -name '*.core' -o -name 'core' \
) -type f
-print > $TMP
89 # \( -name '[#,]*' -o -name '.#*' -o -name a.out \
90 # -o -name '*.CKP' -o -name '.emacs_[0-9]*' \) \
91 # -a -atime +3 -exec rm -f -- {} \; -a -print > $TMP
93 egrep '\.core$|^core$' $TMP > $TMP2
96 echo "Possible core dumps:"
100 # egrep -v '\.core' $TMP > $TMP2
101 # if [ -s $TMP2 ]; then
103 # echo "Deleted files:"
110 if checkyesno run_msgs
; then
114 if checkyesno expire_news
&& [ -f /etc
/news.expire
]; then
118 if checkyesno purge_accounting
&& [ -f /var
/account
/acct
]; then
120 echo "Purging accounting records:"
121 if [ -f /var
/account
/acct
.0.gz
]; then
122 mv /var
/account
/acct
.2.gz
/var
/account
/acct
.3.gz
2>/dev
/null
123 mv /var
/account
/acct
.1.gz
/var
/account
/acct
.2.gz
2>/dev
/null
124 mv /var
/account
/acct
.0.gz
/var
/account
/acct
.1.gz
2>/dev
/null
126 mv /var
/account
/acct
.2 /var
/account
/acct
.3 2>/dev
/null
127 mv /var
/account
/acct
.1 /var
/account
/acct
.2 2>/dev
/null
128 mv /var
/account
/acct
.0 /var
/account
/acct
.1 2>/dev
/null
130 cp /var
/account
/acct
/var
/account
/acct
.0
132 if [ -f /var
/account
/acct
.1.gz
]; then
133 gzip /var
/account
/acct
.0
137 if checkyesno run_calendar
; then
138 calendar
-a > $TMP 2>&1
141 echo "Running calendar:"
147 if checkyesno check_disks
; then
148 if checkyesno show_remote_fs
; then
149 df
-hi -t nokernfs
,procfs
,ptyfs
,null
,fdesc
> $TMP
151 df
-hil -t nokernfs
,procfs
,ptyfs
,null
,fdesc
> $TMP
153 if [ -s /etc
/dumpdates
] ; then
156 if [ -s $TMP -o -s $TMP2 ]; then
158 echo "Checking subsystem status:"
162 cat $TMP |
sed 's/Mounted on/Mount/'
165 if [ -s $TMP2 ]; then
173 for dev
in `iostat -x | awk '/^raid/ { print $1 }'`; do
174 raidctl
-s $dev |
awk '/^.*: failed$/ {print $0}' > $TMP
176 echo "$dev:" >> $TMP2
181 if [ -s $TMP2 ]; then
182 echo "failed RAIDframe component(s):"
188 if checkyesno check_mailq
; then
190 if ! grep -q "queue is empty$" $TMP; then
199 if checkyesno check_network
; then
202 if checkyesno full_netstat
; then
205 netstat
-inv |
awk 'BEGIN {
210 printf("%-8s %12s %6s %12s %6s %6s\n",
211 $1, $(NF-4), $(NF-3), $(NF-2), $(NF-1), $NF);
215 printf("%-8s %12s %6s %12s %6s %6s\n",
216 $1, $(NF-4), $(NF-3), $(NF-2), $(NF-1), $NF);
223 if [ "$t" != '/var/rwho/*' ]; then
228 if checkyesno run_fsck
; then
230 echo "Checking filesystems:"
231 fsck
-n -f ${run_fsck_flags} |
grep -v '^\*\* Phase'
235 if checkyesno run_rdist
&& [ -f /etc
/Distfile
]; then
236 echo "Running rdist:"
237 if [ -d /var
/log
/rdist
]; then
238 logf
=`date +%Y.%b.%d`
239 rdist
-f /etc
/Distfile
2>&1 |
tee /var
/log
/rdist
/$logf
241 rdist
-f /etc
/Distfile
245 if checkyesno run_security
; then
246 SECOUT
="$DAILYDIR/sec"
247 sh
/etc
/security
> "$SECOUT" 2>&1
248 if [ ! -s "$SECOUT" ]; then
249 if checkyesno send_empty_security
; then
250 echo "Nothing to report on $date" > "$SECOUT"
253 echo "Suppressing empty security report."
256 if [ -s "$SECOUT" ]; then
257 mail -s "$host daily insecurity output for $date" \
258 "$MAILTO" < "$SECOUT"
262 if checkyesno run_skeyaudit
; then
263 if [ -s /etc
/skeykeys
]; then
265 echo "Checking remaining s/key OTPs:"
270 if [ -f /etc
/daily.
local ]; then
271 ( .
/etc
/daily.
local ) > $TMP 2>&1
272 if [ -s $TMP ] ; then
273 printf "\nRunning /etc/daily.local:\n"