Home | History | Annotate | Line # | Download | only in etc
daily revision 1.41
      1 #!/bin/sh -
      2 #
      3 #	$NetBSD: daily,v 1.41 2001/10/23 18:39:03 perry 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 DAILYDIR=`mktemp -d /tmp/_daily.XXXXXX` || exit 1
     69 
     70 trap "/bin/rm -rf $DAILYDIR ; exit 0" EXIT INT QUIT
     71 
     72 if ! cd "$DAILYDIR"; then
     73 	echo "Can not cd to $DAILYDIR".
     74 	exit 1
     75 fi
     76 
     77 TMP=daily.$$
     78 TMP2=daily2.$$
     79 
     80 if checkyesno find_core; then
     81 	find / \( ! -fstype local -o -fstype rdonly -o -fstype fdesc \
     82 		-o -fstype kernfs -o -fstype procfs \) -a -prune -o \
     83 		-name 'lost+found' -a -prune -o \
     84 		\( -name '*.core' -o -name 'core' \) -a -print > $TMP
     85 #		\( -name '[#,]*' -o -name '.#*' -o -name a.out \
     86 #		   -o -name '*.CKP' -o -name '.emacs_[0-9]*' \) \
     87 #			-a -atime +3 -exec rm -f -- {} \; -a -print > $TMP
     88 
     89 	egrep '\.core$|^core$' $TMP > $TMP2
     90 	if [ -s $TMP2 ]; then
     91 		echo ""
     92 		echo "Possible core dumps:"
     93 		cat $TMP2
     94 	fi
     95 
     96 #	egrep -v '\.core' $TMP > $TMP2
     97 #	if [ -s $TMP2 ]; then
     98 #		echo ""
     99 #		echo "Deleted files:"
    100 #		cat $TMP2
    101 #	fi
    102 
    103 	rm -f $TMP $TMP2
    104 fi
    105 
    106 if checkyesno run_msgs; then
    107 	msgs -c
    108 fi
    109 
    110 if checkyesno expire_news && [ -f /etc/news.expire ]; then
    111 	/etc/news.expire
    112 fi
    113 
    114 if checkyesno purge_accounting && [ -f /var/account/acct ]; then
    115 	echo ""
    116 	echo "Purging accounting records:"
    117 	mv /var/account/acct.2 /var/account/acct.3
    118 	mv /var/account/acct.1 /var/account/acct.2
    119 	mv /var/account/acct.0 /var/account/acct.1
    120 	cp /var/account/acct /var/account/acct.0
    121 	sa -sq
    122 fi
    123 
    124 if checkyesno run_calendar; then
    125 	calendar -a > $TMP
    126 	if [ -s $TMP ]; then
    127 		echo ""
    128 		echo "Running calendar:"
    129 		cat $TMP
    130 	fi
    131 	rm -f $TMP
    132 fi
    133 
    134 if checkyesno check_uucp && \
    135     [ -d /var/spool/uucp -a -f /usr/libexec/uucp/clean.daily ]; then
    136 	echo ""
    137 	echo "Cleaning up UUCP:"
    138 	su daemon -c /usr/libexec/uucp/clean.daily
    139 fi
    140 
    141 if checkyesno check_disks; then
    142 	df -k > $TMP 
    143 	dump -W > $TMP2
    144 	if [ -s $TMP -o -s $TMP2 ]; then
    145 		echo ""
    146 		echo "Checking subsystem status:"
    147 		echo ""
    148 		echo "disks:"
    149 		if [ -s $TMP ]; then
    150 			cat $TMP
    151 			echo ""
    152 		fi
    153 		if [ -s $TMP2 ]; then
    154 			cat $TMP2
    155 			echo ""
    156 		fi
    157 		echo ""
    158 	fi
    159 fi
    160 
    161 rm -f $TMP $TMP2
    162 
    163 if checkyesno check_mailq; then
    164 	mailq > $TMP
    165 	if ! grep -q "^Mail queue is empty$" $TMP; then
    166 		echo ""
    167 		echo "mail:"
    168 		cat $TMP
    169 	fi
    170 fi
    171 
    172 rm -f $TMP
    173 
    174 if checkyesno check_uucp && [ -d /var/spool/uucp ]; then
    175 	(cd /tmp; su -m uucp -c "uustat -a") > $TMP
    176 	if [ -s $TMP ]; then
    177 		echo ""
    178 		echo "uucp:"
    179 		cat $TMP
    180 	fi
    181 fi
    182 
    183 rm -f $TMP
    184 
    185 if checkyesno check_network; then
    186 	echo ""
    187 	echo "network:"
    188 	netstat -inv
    189 	echo ""
    190 	t=/var/rwho/*
    191 	if [ "$t" != '/var/rwho/*' ]; then
    192 		ruptime
    193 	fi
    194 fi
    195 
    196 if checkyesno run_fsck; then
    197 	echo ""
    198 	echo "Checking filesystems:"
    199 	fsck -n -f | grep -v '^\*\* Phase'
    200 fi
    201 
    202 echo ""
    203 if checkyesno run_rdist && [ -f /etc/Distfile ]; then
    204 	echo "Running rdist:"
    205 	if [ -d /var/log/rdist ]; then
    206 		logf=`date +%Y.%b.%d`
    207 		rdist -f /etc/Distfile 2>&1 | tee /var/log/rdist/$logf
    208 	else
    209 		rdist -f /etc/Distfile 
    210 	fi
    211 fi
    212 
    213 if checkyesno run_security; then
    214 	SECOUT="$DAILYDIR/sec"
    215 	sh /etc/security 2>&1 > "$SECOUT"
    216 	if [ ! -s "$SECOUT" ]; then
    217 		echo "Nothing to report on $date" > "$SECOUT"
    218 	fi
    219 	mail -s "$host daily insecurity output for $date" $MAILTO < "$SECOUT"
    220 fi
    221 
    222 if checkyesno run_skeyaudit; then
    223 	echo ""
    224 	echo "Checking remaining s/key OTPs:"
    225 	skeyaudit
    226 fi
    227 
    228 if [ -f /etc/daily.local ]; then
    229 	echo ""
    230 	echo "Running /etc/daily.local:"
    231 	. /etc/daily.local
    232 fi
    233