NetBSD/etc/daily

234 lines
4.7 KiB
Plaintext
Raw Normal View History

1993-03-21 12:45:37 +03:00
#!/bin/sh -
#
# $NetBSD: daily,v 1.45 2001/12/18 00:51:16 lukem Exp $
# @(#)daily 8.2 (Berkeley) 1/25/94
1993-03-21 12:45:37 +03:00
#
1998-07-16 09:21:56 +04:00
export PATH=/bin:/usr/bin:/sbin:/usr/sbin
umask 077
if [ -s /etc/daily.conf ]; then
. /etc/daily.conf
fi
1997-02-15 13:02:07 +03:00
host=`hostname`
date=`date`
1993-03-21 12:45:37 +03:00
echo "To: ${MAILTO:-root}"
echo "Subject: $host daily output for $date"
echo ""
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
if [ -z "$MAILTO" -o "$USER" != "root" ]; then
1998-07-16 09:21:56 +04:00
MAILTO=root
fi
echo ""
echo "Uptime: " `uptime`
# 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.
#
#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 -- {} \;
# find . ! \( -name . -o -name vi.recover \) -type d \
# -mtime +1 -exec rmdir -- {} \; \
# >/dev/null 2>&1; }
#fi
# 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
#if [ -d /var/rwho -a ! -h /var/rwho ] ; then
# cd /var/rwho && {
# find . ! -name . -mtime +7 -exec rm -f -- {} \; ; }
#fi
DAILYDIR=`mktemp -d /tmp/_daily.XXXXXX` || exit 1
trap "/bin/rm -rf $DAILYDIR ; exit 0" EXIT INT QUIT
if ! cd "$DAILYDIR"; then
echo "Can not cd to $DAILYDIR".
exit 1
fi
1993-03-21 12:45:37 +03:00
TMP=daily.$$
TMP2=daily2.$$
1998-01-26 15:02:43 +03:00
if checkyesno find_core; then
find / \( ! -fstype local -o -fstype rdonly -o -fstype fdesc \
-o -fstype null \
-o -fstype kernfs -o -fstype procfs \) -a -prune -o \
-name 'lost+found' -a -prune -o \
\( -name '*.core' -o -name 'core' \) -a -print > $TMP
# \( -name '[#,]*' -o -name '.#*' -o -name a.out \
# -o -name '*.CKP' -o -name '.emacs_[0-9]*' \) \
# -a -atime +3 -exec rm -f -- {} \; -a -print > $TMP
egrep '\.core$|^core$' $TMP > $TMP2
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
msgs -c
fi
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
echo ""
echo "Purging accounting records:"
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
cp /var/account/acct /var/account/acct.0
sa -sq
fi
1993-03-21 12:45:37 +03:00
1998-01-26 15:02:43 +03:00
if checkyesno run_calendar; then
calendar -a > $TMP
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_uucp && \
[ -d /var/spool/uucp -a -f /usr/libexec/uucp/clean.daily ]; then
1993-03-21 12:45:37 +03:00
echo ""
echo "Cleaning up UUCP:"
su daemon -c /usr/libexec/uucp/clean.daily
1993-03-21 12:45:37 +03:00
fi
1998-01-26 15:02:43 +03:00
if checkyesno check_disks; then
df -ki > $TMP
2001-10-23 21:34:53 +04:00
dump -W > $TMP2
if [ -s $TMP -o -s $TMP2 ]; then
echo ""
echo "Checking subsystem status:"
echo ""
echo "disks:"
if [ -s $TMP ]; then
cat $TMP
echo ""
fi
if [ -s $TMP2 ]; then
cat $TMP2
echo ""
fi
echo ""
fi
fi
1993-03-21 12:45:37 +03:00
rm -f $TMP $TMP2
1993-03-21 12:45:37 +03:00
1998-01-26 15:02:43 +03:00
if checkyesno check_mailq; then
mailq > $TMP
if ! grep -q "queue is empty$" $TMP; then
echo ""
echo "mail:"
cat $TMP
fi
fi
1993-03-21 12:45:37 +03:00
rm -f $TMP
1998-01-26 15:02:43 +03:00
if checkyesno check_uucp && [ -d /var/spool/uucp ]; then
(cd /tmp; su -m uucp -c "uustat -a") > $TMP
if [ -s $TMP ]; then
echo ""
echo "uucp:"
cat $TMP
fi
1993-03-21 12:45:37 +03:00
fi
rm -f $TMP
1993-03-21 12:45:37 +03:00
1998-01-26 15:02:43 +03:00
if checkyesno check_network; then
echo ""
echo "network:"
netstat -inv
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
echo ""
echo "Checking filesystems:"
fsck -n -f | grep -v '^\*\* Phase'
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
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
SECOUT="$DAILYDIR/sec"
sh /etc/security 2>&1 > "$SECOUT"
if [ ! -s "$SECOUT" ]; then
echo "Nothing to report on $date" > "$SECOUT"
fi
mail -s "$host daily insecurity output for $date" $MAILTO < "$SECOUT"
fi
if checkyesno run_skeyaudit; then
echo ""
echo "Checking remaining s/key OTPs:"
skeyaudit
fi
if [ -f /etc/daily.local ]; then
echo ""
echo "Running /etc/daily.local:"
. /etc/daily.local
fi