1993-03-21 12:45:37 +03:00
|
|
|
#!/bin/sh -
|
|
|
|
#
|
2009-03-29 20:04:15 +04:00
|
|
|
# $NetBSD: daily,v 1.72 2009/03/29 16:04:15 perry Exp $
|
1997-05-30 09:18:59 +04:00
|
|
|
# @(#)daily 8.2 (Berkeley) 1/25/94
|
1993-03-21 12:45:37 +03:00
|
|
|
#
|
1997-01-05 14:21:09 +03:00
|
|
|
|
1998-07-16 09:21:56 +04:00
|
|
|
export PATH=/bin:/usr/bin:/sbin:/usr/sbin
|
1998-09-15 09:06:30 +04:00
|
|
|
umask 077
|
|
|
|
|
|
|
|
if [ -s /etc/daily.conf ]; then
|
|
|
|
. /etc/daily.conf
|
|
|
|
fi
|
|
|
|
|
1997-02-15 13:02:07 +03:00
|
|
|
host=`hostname`
|
1998-09-15 09:06:30 +04:00
|
|
|
date=`date`
|
2004-04-02 17:13:47 +04:00
|
|
|
rcvar_manpage='daily.conf(5)'
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1998-09-15 09:06:30 +04:00
|
|
|
echo "To: ${MAILTO:-root}"
|
|
|
|
echo "Subject: $host daily output for $date"
|
|
|
|
echo ""
|
1997-01-05 14:21:09 +03:00
|
|
|
|
1998-01-26 15:02:43 +03:00
|
|
|
if [ -f /etc/rc.subr ]; then
|
|
|
|
. /etc/rc.subr
|
|
|
|
else
|
|
|
|
echo "Can't read /etc/rc.subr; aborting."
|
|
|
|
exit 1;
|
|
|
|
fi
|
|
|
|
|
1997-07-11 04:36:55 +04:00
|
|
|
if [ -z "$MAILTO" -o "$USER" != "root" ]; then
|
1998-07-16 09:21:56 +04:00
|
|
|
MAILTO=root
|
1997-07-11 04:36:55 +04:00
|
|
|
fi
|
|
|
|
|
1997-06-23 05:45:21 +04:00
|
|
|
echo ""
|
|
|
|
echo "Uptime: " `uptime`
|
|
|
|
|
1999-01-06 06:24:06 +03:00
|
|
|
# Uncommenting any of the finds below would open up a race condition attack
|
|
|
|
# based on symlinks, potentially allowing removal of any file on the system.
|
|
|
|
#
|
1996-07-03 03:10:35 +04:00
|
|
|
#echo ""
|
|
|
|
#echo "Removing scratch and junk files:"
|
|
|
|
#if [ -d /tmp -a ! -h /tmp ]; then
|
|
|
|
# cd /tmp && {
|
|
|
|
# find . -type f -atime +3 -exec rm -f -- {} \;
|
|
|
|
# find . ! -name . -type d -mtime +1 -exec rmdir -- {} \; \
|
|
|
|
# >/dev/null 2>&1; }
|
|
|
|
#fi
|
|
|
|
|
|
|
|
#if [ -d /var/tmp -a ! -h /var/tmp ]; then
|
|
|
|
# cd /var/tmp && {
|
|
|
|
# find . ! -name . -atime +7 -exec rm -f -- {} \;
|
2001-04-23 00:34:48 +04:00
|
|
|
# find . ! \( -name . -o -name vi.recover \) -type d \
|
|
|
|
# -mtime +1 -exec rmdir -- {} \; \
|
1996-07-03 03:10:35 +04:00
|
|
|
# >/dev/null 2>&1; }
|
|
|
|
#fi
|
1994-02-19 10:54:08 +03:00
|
|
|
|
1996-03-25 12:23:15 +03:00
|
|
|
# Additional junk directory cleanup would go like this:
|
|
|
|
#if [ -d /scratch -a ! -h /scratch ]; then
|
|
|
|
# cd /scratch && {
|
|
|
|
# find . ! -name . -atime +1 -exec rm -f -- {} \;
|
|
|
|
# find . ! -name . -type d -mtime +1 -exec rmdir -- {} \; \
|
|
|
|
# >/dev/null 2>&1; }
|
|
|
|
#fi
|
1994-02-19 10:54:08 +03:00
|
|
|
|
1996-07-03 03:10:35 +04:00
|
|
|
#if [ -d /var/rwho -a ! -h /var/rwho ] ; then
|
|
|
|
# cd /var/rwho && {
|
|
|
|
# find . ! -name . -mtime +7 -exec rm -f -- {} \; ; }
|
|
|
|
#fi
|
1994-02-19 10:54:08 +03:00
|
|
|
|
2007-06-06 17:30:47 +04:00
|
|
|
DAILYDIR=$(mktemp -d -t _daily) || exit 1
|
1994-02-19 10:54:08 +03:00
|
|
|
|
2001-06-18 14:54:02 +04:00
|
|
|
trap "/bin/rm -rf $DAILYDIR ; exit 0" EXIT INT QUIT
|
1994-02-19 10:54:08 +03:00
|
|
|
|
2001-06-18 14:54:02 +04:00
|
|
|
if ! cd "$DAILYDIR"; then
|
|
|
|
echo "Can not cd to $DAILYDIR".
|
1997-01-05 14:21:09 +03:00
|
|
|
exit 1
|
|
|
|
fi
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-01-05 14:21:09 +03:00
|
|
|
TMP=daily.$$
|
|
|
|
TMP2=daily2.$$
|
|
|
|
|
1998-01-26 15:02:43 +03:00
|
|
|
if checkyesno find_core; then
|
2004-09-28 19:03:58 +04:00
|
|
|
# Turn "foo !bar bax" into "-fstype foo -o ! -fstype bar -o -fstype bax"
|
|
|
|
ignfstypes=`echo $find_core_ignore_fstypes | \
|
|
|
|
sed -e's/\(!*\)\([^[:space:]]\{1,\}\)/-o \1 -fstype \2/g' \
|
|
|
|
-e's/^-o //'`
|
|
|
|
find / \( $ignfstypes \) -prune -o \
|
2003-02-04 08:31:18 +03:00
|
|
|
-name 'lost+found' -prune -o \
|
|
|
|
\( -name '*.core' -o -name 'core' \) -type f -print > $TMP
|
1997-01-05 14:21:09 +03:00
|
|
|
# \( -name '[#,]*' -o -name '.#*' -o -name a.out \
|
|
|
|
# -o -name '*.CKP' -o -name '.emacs_[0-9]*' \) \
|
|
|
|
# -a -atime +3 -exec rm -f -- {} \; -a -print > $TMP
|
|
|
|
|
1998-06-29 01:37:59 +04:00
|
|
|
egrep '\.core$|^core$' $TMP > $TMP2
|
1997-01-05 14:21:09 +03:00
|
|
|
if [ -s $TMP2 ]; then
|
|
|
|
echo ""
|
|
|
|
echo "Possible core dumps:"
|
|
|
|
cat $TMP2
|
|
|
|
fi
|
|
|
|
|
|
|
|
# egrep -v '\.core' $TMP > $TMP2
|
|
|
|
# if [ -s $TMP2 ]; then
|
|
|
|
# echo ""
|
|
|
|
# echo "Deleted files:"
|
|
|
|
# cat $TMP2
|
|
|
|
# fi
|
|
|
|
|
|
|
|
rm -f $TMP $TMP2
|
|
|
|
fi
|
1994-02-19 10:56:02 +03:00
|
|
|
|
1998-01-26 15:02:43 +03:00
|
|
|
if checkyesno run_msgs; then
|
1997-01-05 14:21:09 +03:00
|
|
|
msgs -c
|
|
|
|
fi
|
1994-02-18 08:40:22 +03:00
|
|
|
|
1998-01-26 15:02:43 +03:00
|
|
|
if checkyesno expire_news && [ -f /etc/news.expire ]; then
|
1993-03-21 12:45:37 +03:00
|
|
|
/etc/news.expire
|
|
|
|
fi
|
|
|
|
|
1998-01-26 15:02:43 +03:00
|
|
|
if checkyesno purge_accounting && [ -f /var/account/acct ]; then
|
1997-05-30 09:18:59 +04:00
|
|
|
echo ""
|
|
|
|
echo "Purging accounting records:"
|
2004-03-29 06:17:26 +04:00
|
|
|
if [ -f /var/account/acct.0.gz ]; then
|
|
|
|
mv /var/account/acct.2.gz /var/account/acct.3.gz 2>/dev/null
|
|
|
|
mv /var/account/acct.1.gz /var/account/acct.2.gz 2>/dev/null
|
|
|
|
mv /var/account/acct.0.gz /var/account/acct.1.gz 2>/dev/null
|
|
|
|
else
|
|
|
|
mv /var/account/acct.2 /var/account/acct.3 2>/dev/null
|
|
|
|
mv /var/account/acct.1 /var/account/acct.2 2>/dev/null
|
|
|
|
mv /var/account/acct.0 /var/account/acct.1 2>/dev/null
|
|
|
|
fi
|
1997-05-30 09:18:59 +04:00
|
|
|
cp /var/account/acct /var/account/acct.0
|
|
|
|
sa -sq
|
2004-03-29 06:17:26 +04:00
|
|
|
if [ -f /var/account/acct.1.gz ]; then
|
|
|
|
gzip /var/account/acct.0
|
|
|
|
fi
|
1994-02-26 06:29:23 +03:00
|
|
|
fi
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1998-01-26 15:02:43 +03:00
|
|
|
if checkyesno run_calendar; then
|
2003-10-01 09:34:50 +04:00
|
|
|
calendar -a > $TMP 2>&1
|
1997-01-05 14:21:09 +03:00
|
|
|
if [ -s $TMP ]; then
|
|
|
|
echo ""
|
|
|
|
echo "Running calendar:"
|
|
|
|
cat $TMP
|
|
|
|
fi
|
|
|
|
rm -f $TMP
|
|
|
|
fi
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1998-01-26 15:02:43 +03:00
|
|
|
if checkyesno check_disks; then
|
2003-12-08 04:17:37 +03:00
|
|
|
if checkyesno show_remote_fs; then
|
2009-03-29 20:04:15 +04:00
|
|
|
df -hi -t nokernfs,procfs,ptyfs,null,fdesc > $TMP
|
2003-12-08 04:17:37 +03:00
|
|
|
else
|
2009-03-29 20:04:15 +04:00
|
|
|
df -hil -t nokernfs,procfs,ptyfs,null,fdesc > $TMP
|
2003-12-08 04:17:37 +03:00
|
|
|
fi
|
2003-12-07 19:35:04 +03:00
|
|
|
if [ -s /etc/dumpdates ] ; then
|
|
|
|
dump -W > $TMP2
|
|
|
|
fi
|
1997-01-05 14:21:09 +03:00
|
|
|
if [ -s $TMP -o -s $TMP2 ]; then
|
|
|
|
echo ""
|
|
|
|
echo "Checking subsystem status:"
|
|
|
|
echo ""
|
|
|
|
echo "disks:"
|
|
|
|
if [ -s $TMP ]; then
|
2005-08-22 18:24:45 +04:00
|
|
|
cat $TMP | sed 's/Mounted on/Mount/'
|
1997-01-05 14:21:09 +03:00
|
|
|
echo ""
|
|
|
|
fi
|
|
|
|
if [ -s $TMP2 ]; then
|
|
|
|
cat $TMP2
|
|
|
|
echo ""
|
|
|
|
fi
|
|
|
|
echo ""
|
|
|
|
fi
|
2002-01-28 01:08:50 +03:00
|
|
|
rm -f $TMP $TMP2
|
|
|
|
touch $TMP2
|
|
|
|
for dev in `iostat -x | awk '/^raid/ { print $1 }'`; do
|
|
|
|
raidctl -s $dev | awk '/^.*: failed$/ {print $0}' > $TMP
|
|
|
|
if [ -s $TMP ]; then
|
|
|
|
echo "$dev:" >> $TMP2
|
|
|
|
cat $TMP >> $TMP2
|
|
|
|
fi
|
|
|
|
rm -f $TMP
|
|
|
|
done
|
|
|
|
if [ -s $TMP2 ]; then
|
|
|
|
echo "failed RAIDframe component(s):"
|
|
|
|
cat $TMP2
|
|
|
|
fi
|
|
|
|
rm -f $TMP2
|
1997-01-05 14:21:09 +03:00
|
|
|
fi
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1998-01-26 15:02:43 +03:00
|
|
|
if checkyesno check_mailq; then
|
1997-01-05 14:21:09 +03:00
|
|
|
mailq > $TMP
|
2001-12-18 03:48:05 +03:00
|
|
|
if ! grep -q "queue is empty$" $TMP; then
|
1997-01-05 14:21:09 +03:00
|
|
|
echo ""
|
|
|
|
echo "mail:"
|
|
|
|
cat $TMP
|
|
|
|
fi
|
|
|
|
fi
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-01-05 14:21:09 +03:00
|
|
|
rm -f $TMP
|
|
|
|
|
1998-01-26 15:02:43 +03:00
|
|
|
if checkyesno check_network; then
|
1997-01-05 14:21:09 +03:00
|
|
|
echo ""
|
|
|
|
echo "network:"
|
2003-12-08 01:22:15 +03:00
|
|
|
if checkyesno full_netstat; then
|
|
|
|
netstat -inv
|
|
|
|
else
|
2004-05-28 07:55:30 +04:00
|
|
|
netstat -inv | awk 'BEGIN {
|
2003-12-08 01:22:15 +03:00
|
|
|
ifs[""] = 0;
|
|
|
|
}
|
|
|
|
/^[^\*]* / {
|
|
|
|
if (NR == 1) {
|
2006-05-27 12:56:47 +04:00
|
|
|
printf("%-8s %12s %6s %12s %6s %6s\n",
|
2003-12-08 01:22:15 +03:00
|
|
|
$1, $(NF-4), $(NF-3), $(NF-2), $(NF-1), $NF);
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
if (!($1 in ifs)) {
|
2006-05-27 12:56:47 +04:00
|
|
|
printf("%-8s %12s %6s %12s %6s %6s\n",
|
2003-12-08 01:22:15 +03:00
|
|
|
$1, $(NF-4), $(NF-3), $(NF-2), $(NF-1), $NF);
|
|
|
|
ifs[$1] = 1;
|
|
|
|
}
|
|
|
|
}'
|
|
|
|
fi
|
1997-01-05 14:21:09 +03:00
|
|
|
echo ""
|
|
|
|
t=/var/rwho/*
|
|
|
|
if [ "$t" != '/var/rwho/*' ]; then
|
|
|
|
ruptime
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
1998-01-26 15:02:43 +03:00
|
|
|
if checkyesno run_fsck; then
|
1997-01-05 14:21:09 +03:00
|
|
|
echo ""
|
|
|
|
echo "Checking filesystems:"
|
2008-08-30 14:53:22 +04:00
|
|
|
fsck -n -f ${run_fsck_flags} | grep -v '^\*\* Phase'
|
1997-01-05 14:21:09 +03:00
|
|
|
fi
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
echo ""
|
1998-01-26 15:02:43 +03:00
|
|
|
if checkyesno run_rdist && [ -f /etc/Distfile ]; then
|
1993-03-21 12:45:37 +03:00
|
|
|
echo "Running rdist:"
|
1997-02-15 13:02:07 +03:00
|
|
|
if [ -d /var/log/rdist ]; then
|
2000-01-07 06:52:23 +03:00
|
|
|
logf=`date +%Y.%b.%d`
|
1997-02-15 13:02:07 +03:00
|
|
|
rdist -f /etc/Distfile 2>&1 | tee /var/log/rdist/$logf
|
|
|
|
else
|
|
|
|
rdist -f /etc/Distfile
|
|
|
|
fi
|
1993-03-21 12:45:37 +03:00
|
|
|
fi
|
|
|
|
|
1998-01-26 15:02:43 +03:00
|
|
|
if checkyesno run_security; then
|
2001-06-18 14:54:02 +04:00
|
|
|
SECOUT="$DAILYDIR/sec"
|
2002-12-25 05:41:03 +03:00
|
|
|
sh /etc/security > "$SECOUT" 2>&1
|
2001-06-18 14:54:02 +04:00
|
|
|
if [ ! -s "$SECOUT" ]; then
|
2003-02-22 01:35:46 +03:00
|
|
|
if checkyesno send_empty_security; then
|
|
|
|
echo "Nothing to report on $date" > "$SECOUT"
|
|
|
|
else
|
|
|
|
echo ""
|
2003-12-28 19:34:03 +03:00
|
|
|
echo "Suppressing empty security report."
|
2003-02-22 01:35:46 +03:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
if [ -s "$SECOUT" ]; then
|
|
|
|
mail -s "$host daily insecurity output for $date" \
|
2005-01-09 16:07:14 +03:00
|
|
|
"$MAILTO" < "$SECOUT"
|
1998-09-15 09:06:30 +04:00
|
|
|
fi
|
1997-01-05 14:21:09 +03:00
|
|
|
fi
|
|
|
|
|
2000-08-25 05:11:42 +04:00
|
|
|
if checkyesno run_skeyaudit; then
|
2003-12-07 19:35:04 +03:00
|
|
|
if [ -s /etc/skeykeys ]; then
|
|
|
|
echo ""
|
|
|
|
echo "Checking remaining s/key OTPs:"
|
|
|
|
skeyaudit
|
|
|
|
fi
|
2000-08-25 05:11:42 +04:00
|
|
|
fi
|
|
|
|
|
2000-01-10 20:03:49 +03:00
|
|
|
if [ -f /etc/daily.local ]; then
|
2006-12-18 02:24:09 +03:00
|
|
|
( . /etc/daily.local ) > $TMP 2>&1
|
2004-04-09 21:35:21 +04:00
|
|
|
if [ -s $TMP ] ; then
|
|
|
|
printf "\nRunning /etc/daily.local:\n"
|
|
|
|
cat $TMP
|
|
|
|
fi
|
|
|
|
rm -f $TMP
|
2000-01-10 20:03:49 +03:00
|
|
|
fi
|