#!/bin/sh -
#
#	@(#)monthly	8.1 (Berkeley) 6/9/93
#

PATH=/bin:/usr/bin:/sbin:/usr/sbin
host=`hostname -s`
echo "Subject: $host monthly run output"

echo ""
echo "Doing login accounting:"
if type sort>/dev/null; then 
    ac -p | sort -nr +1
else
    ac -p
fi

echo ""
echo -n "Rotating log files:"
cd /var/log
for i in wtmp; do
    if [ -f "${i}" ]; then
	echo -n " $i"
	if [ -x /usr/bin/gzip ]; then gzext=".gz"; else gzext=""; fi
	if [ -f "${i}.3${gzext}" ]; then mv -f "${i}.3${gzext}" "${i}.4${gzext}"; fi
	if [ -f "${i}.2${gzext}" ]; then mv -f "${i}.2${gzext}" "${i}.3${gzext}"; fi
	if [ -f "${i}.1${gzext}" ]; then mv -f "${i}.1${gzext}" "${i}.2${gzext}"; fi
	if [ -f "${i}.0${gzext}" ]; then mv -f "${i}.0${gzext}" "${i}.1${gzext}"; fi
	if [ -f "${i}" ]; then mv -f "${i}" "${i}.0" && if [ -x /usr/bin/gzip ]; then gzip -9 "${i}.0"; fi; fi
	touch "${i}" && chmod 640 "${i}" && chown root:admin "${i}"
    fi
done
if [ -f /var/run/syslog.pid ]; then kill -HUP $(cat /var/run/syslog.pid | head -1); fi
echo ""

if [ -f /etc/monthly.local ]; then
    echo ""
    echo "Running monthly.local:"
    sh /etc/monthly.local
fi
