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