Home | History | Annotate | Line # | Download | only in etc
daily revision 1.27
      1 #!/bin/sh -
      2 #
      3 #	$NetBSD: daily,v 1.27 1998/07/16 05:21:56 mycroft Exp $
      4 #	@(#)daily	8.2 (Berkeley) 1/25/94
      5 #
      6 
      7 export PATH=/bin:/usr/bin:/sbin:/usr/sbin
      8 host=`hostname`
      9 echo "Subject: $host daily run output"
     10 
     11 umask 077
     12 
     13 if [ -f /etc/rc.subr ]; then
     14 	. /etc/rc.subr
     15 else
     16 	echo "Can't read /etc/rc.subr; aborting."
     17 	exit 1;
     18 fi
     19 
     20 if [ -z "$MAILTO" -o "$USER" != "root" ]; then
     21 	MAILTO=root
     22 fi
     23 
     24 if [ -s /etc/daily.conf ]; then
     25 	. /etc/daily.conf
     26 fi
     27 
     28 echo ""
     29 echo "Uptime: " `uptime`
     30 
     31 #echo ""
     32 #echo "Removing scratch and junk files:"
     33 #if [ -d /tmp -a ! -h /tmp ]; then
     34 #	cd /tmp && {
     35 #	find . -type f -atime +3 -exec rm -f -- {} \;
     36 #	find . ! -name . -type d -mtime +1 -exec rmdir -- {} \; \
     37 #	    >/dev/null 2>&1; }
     38 #fi
     39 
     40 #if [ -d /var/tmp -a ! -h /var/tmp ]; then
     41 #	cd /var/tmp && {
     42 #	find . ! -name . -atime +7 -exec rm -f -- {} \;
     43 #	find . ! -name . -type d -mtime +1 -exec rmdir -- {} \; \
     44 #	    >/dev/null 2>&1; }
     45 #fi
     46 
     47 # Additional junk directory cleanup would go like this:
     48 #if [ -d /scratch -a ! -h /scratch ]; then
     49 #	cd /scratch && {
     50 #	find . ! -name . -atime +1 -exec rm -f -- {} \;
     51 #	find . ! -name . -type d -mtime +1 -exec rmdir -- {} \; \
     52 #	    >/dev/null 2>&1; }
     53 #fi
     54 
     55 #if [ -d /var/rwho -a ! -h /var/rwho ] ; then
     56 #	cd /var/rwho && {
     57 #	find . ! -name . -mtime +7 -exec rm -f -- {} \; ; }
     58 #fi
     59 
     60 TMPDIR=/tmp/_daily.$$
     61 
     62 if ! mkdir $TMPDIR; then
     63 	echo can not create $TMPDIR.
     64 	exit 1
     65 fi
     66 
     67 if ! cd $TMPDIR; then
     68 	echo can not cd to $TMPDIR.
     69 	exit 1
     70 fi
     71 
     72 TMP=daily.$$
     73 TMP2=daily2.$$
     74 
     75 if checkyesno find_core; then
     76 	find / \( ! -fstype local -o -fstype rdonly -o -fstype fdesc \
     77 		-o -fstype kernfs -o -fstype procfs \) -a -prune -o \
     78 		-name 'lost+found' -a -prune -o \
     79 		\( -name '*.core' -o -name 'core' \) -a -print > $TMP
     80 #		\( -name '[#,]*' -o -name '.#*' -o -name a.out \
     81 #		   -o -name '*.CKP' -o -name '.emacs_[0-9]*' \) \
     82 #			-a -atime +3 -exec rm -f -- {} \; -a -print > $TMP
     83 
     84 	egrep '\.core$|^core$' $TMP > $TMP2
     85 	if [ -s $TMP2 ]; then
     86 		echo ""
     87 		echo "Possible core dumps:"
     88 		cat $TMP2
     89 	fi
     90 
     91 #	egrep -v '\.core' $TMP > $TMP2
     92 #	if [ -s $TMP2 ]; then
     93 #		echo ""
     94 #		echo "Deleted files:"
     95 #		cat $TMP2
     96 #	fi
     97 
     98 	rm -f $TMP $TMP2
     99 fi
    100 
    101 if checkyesno run_msgs; then
    102 	msgs -c
    103 fi
    104 
    105 if checkyesno expire_news && [ -f /etc/news.expire ]; then
    106 	/etc/news.expire
    107 fi
    108 
    109 if checkyesno purge_accounting && [ -f /var/account/acct ]; then
    110 	echo ""
    111 	echo "Purging accounting records:"
    112 	mv /var/account/acct.2 /var/account/acct.3
    113 	mv /var/account/acct.1 /var/account/acct.2
    114 	mv /var/account/acct.0 /var/account/acct.1
    115 	cp /var/account/acct /var/account/acct.0
    116 	sa -sq
    117 fi
    118 
    119 if checkyesno run_calendar; then
    120 	calendar -a > $TMP
    121 	if [ -s $TMP ]; then
    122 		echo ""
    123 		echo "Running calendar:"
    124 		cat $TMP
    125 	fi
    126 	rm -f $TMP
    127 fi
    128 
    129 if checkyesno check_uucp && \
    130     [ -d /var/spool/uucp -a -f /usr/libexec/uucp/clean.daily ]; then
    131 	echo ""
    132 	echo "Cleaning up UUCP:"
    133 	su daemon -c /usr/libexec/uucp/clean.daily
    134 fi
    135 
    136 if checkyesno check_disks; then
    137 	df -k > $TMP 
    138 	dump W > $TMP2
    139 	if [ -s $TMP -o -s $TMP2 ]; then
    140 		echo ""
    141 		echo "Checking subsystem status:"
    142 		echo ""
    143 		echo "disks:"
    144 		if [ -s $TMP ]; then
    145 			cat $TMP
    146 			echo ""
    147 		fi
    148 		if [ -s $TMP2 ]; then
    149 			cat $TMP2
    150 			echo ""
    151 		fi
    152 		echo ""
    153 	fi
    154 fi
    155 
    156 rm -f $TMP $TMP2
    157 
    158 if checkyesno check_mailq; then
    159 	mailq > $TMP
    160 	if ! grep -q "^Mail queue is empty$" $TMP; then
    161 		echo ""
    162 		echo "mail:"
    163 		cat $TMP
    164 	fi
    165 fi
    166 
    167 rm -f $TMP
    168 
    169 if checkyesno check_uucp && [ -d /var/spool/uucp ]; then
    170 	uustat -a > $TMP
    171 	if [ -s $TMP ]; then
    172 		echo ""
    173 		echo "uucp:"
    174 		cat $TMP
    175 	fi
    176 fi
    177 
    178 rm -f $TMP
    179 
    180 if checkyesno check_network; then
    181 	echo ""
    182 	echo "network:"
    183 	netstat -i
    184 	echo ""
    185 	t=/var/rwho/*
    186 	if [ "$t" != '/var/rwho/*' ]; then
    187 		ruptime
    188 	fi
    189 fi
    190 
    191 if checkyesno run_fsck; then
    192 	echo ""
    193 	echo "Checking filesystems:"
    194 	fsck -n | grep -v '^\*\* Phase'
    195 fi
    196 
    197 echo ""
    198 if checkyesno run_rdist && [ -f /etc/Distfile ]; then
    199 	echo "Running rdist:"
    200 	if [ -d /var/log/rdist ]; then
    201 		logf=`date +%Y.%b.%e`
    202 		rdist -f /etc/Distfile 2>&1 | tee /var/log/rdist/$logf
    203 	else
    204 		rdist -f /etc/Distfile 
    205 	fi
    206 fi
    207 
    208 if checkyesno run_security; then
    209 	sh /etc/security 2>&1 | mail -s "$host daily insecurity output" $MAILTO
    210 fi
    211 
    212 rm -rf $TMPDIR
    213