# @(#) maint 3.0 16may94 Morgan_Davis @(#)

clear; banner -b " Maint" "   3.0"
set _="^M----------------------------^M"

echo "$argv[0]: reporting device usage..."
echo "$_\Device Usage Summary$_" >$tmpdir/maint.report
df >>$tmpdir/maint.report

echo "$_\System Usage Summary$_" >>$tmpdir/maint.report
calls -s >>$tmpdir/maint.report

if -f $spool/logs/syslog then
    echo "$argv[0]: processing syslog..."
    grep -v " -----" $spool/logs/syslog >$tmpdir/tmplog
    if -f $tmpdir/tmplog then
        echo "$_\Human Callers$_" >>$tmpdir/maint.report
        add $tmpdir/tmplog $tmpdir/maint.report
        rm $tmpdir/tmplog
    endif
endif

if -f $spool/logs/adduser.log then
    echo "$argv[0]: processing adduser.log..."
    echo "$_\New Users$_" >>$tmpdir/maint.report
    add $spool/logs/adduser.log $tmpdir/maint.report
endif

flip -a
if -f $home/rmip && "$argv[1]" == "-r" then
    rmuser -p -f $home/rmip
    echo "$_\Expired Accounts$_" >>$tmpdir/maint.report
    add $home/rmip $tmpdir/maint.report
    rm $home/rmip
else
    if -f $home/rmip.big then
        echo "$_\Accounts To Expire Manually$_" >>$tmpdir/maint.report
        add $home/rmip.big $tmpdir/maint.report
    endif
endif

if -f $spool/logs/servlog then
    echo "$argv[0]: processing servlog..."
    echo "$_\Server Requests$_" >>$tmpdir/maint.report
    add $spool/logs/servlog $tmpdir/maint.report
endif

if -f $spool/logs/mdsslog then
    uutraf >$tmpdir/tmplog
    if -f $tmpdir/tmplog then
        echo "$_\Network Traffic$_" >>$tmpdir/maint.report
        add $tmpdir/tmplog $tmpdir/maint.report
        echo "$argv[0]: scanning mdsslog for errors and alerts..."
        rm $tmpdir/tmplog
        grep "<ERROR" $spool/logs/mdsslog >$tmpdir/tmplog
        grep "<ALERT" $spool/logs/mdsslog >>$tmpdir/tmplog
        if -f $tmpdir/tmplog then
           echo "$_\Network Trouble$_" >>$tmpdir/maint.report
           add $tmpdir/tmplog $tmpdir/maint.report
           rm $tmpdir/tmplog
        endif
    endif
endif

if -f $spool/logs/newslog then
    echo "$argv[0]: processing newslog..."
    grep "<" $spool/logs/newslog >$tmpdir/tmplog
    if -f $tmpdir/tmplog then
        echo "$_\News Processing Errors$_" >>$tmpdir/maint.report
        add $tmpdir/tmplog $tmpdir/maint.report
        rm $tmpdir/tmplog
    endif
endif

if -f $tmpdir/maint.report then
    set _="Maintenance Report for $time[1]-$date[2]-$time[3]"
    rcp -a $tmpdir/maint.report root -s "$_"
    rm $tmpdir/maint.report
endif

sendmail
if -f $/sys/mail/guest then rm $/sys/mail/guest
if -f $/sys/mail/null then rm $/sys/mail/null
unset _; echo $argv[0]:" finished!"
$argv[0]2 $argv[1] $argv[2]
