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