Cover V05, I01
Article
Listing 1
Listing 2
Listing 3
Listing 4
Listing 5
Listing 6

jan96.tar


Listing 4: rmu.sh--reports monthly uptime

#!/bin/sh
#
# rmu - report monthly uptime.
#
# SYNOPSIS
#    /usr/local/etc/rmu [-r] [M [Y]]
#
# DESCRIPTION
#    Calls rst(8L - part of this package) to process and report on
#    the contents of the monthly log.  If no month is specified, it
#    tries to report on the previous month.  rmu mails its results
#    to MAILLST.
#
# OPTIONS
#    -r		Remove daily logs from the month just reported.
#
#    M, Y	1 - 12,  nnnn;  month,  year to report.
#
# FILES
#    D.yyyy.mm.*.Y	Removed if the "-r" option is specified.
#
#    /tmp/cml.$$.date	Temporary for date(1) output; removed after
#			used.
#
#    /usr/local/etc/rmu_mail
#			If this file exists,  contents are used to
#			override the MAILST installation constant.
#
# LIMITATIONS
#    rmu is naive about the [M, Y] option;  it assumes you entered
#    a valid number for a month,  year.

#set -x

#
# Installation constants
BINDIR=/usr/local/bin
SHLDIR=/usr/local/etc
EXEDIR=$SHLDIR
LOGDIR=/var/log
MAILST="flt whg"
REMOVE=F
SFX=

#
# Direct paths to programs used
CAT=/bin/cat
CUT=/bin/cut
DATE=/bin/date
ECHO=/bin/echo
LS=/bin/ls
RM=/bin/rm
TR=/bin/tr

#
# Begin.
#
#
# Get current date.
$DATE '+%y %m %d %H %M %S' > /tmp/cml.$$.date
YY=`$CUT -d' ' -f1 /tmp/cml.$$.date`
MM=`$CUT -d' ' -f2 /tmp/cml.$$.date`
DD=`$CUT -d' ' -f3 /tmp/cml.$$.date`
HH=`$CUT -d' ' -f4 /tmp/cml.$$.date`
MN=`$CUT -d' ' -f5 /tmp/cml.$$.date`
SS=`$CUT -d' ' -f6 /tmp/cml.$$.date`
$RM -f /tmp/cml.$$.date
YY=`expr $YY + 1900`
#
# Deal with command line argument(s).
WHERE=`$ECHO "$0" | cut -d. -f3`
if  [ X"$WHERE" = X"sh" ]
then
EXEDIR=.
fi

if  [ -f /usr/local/etc/rmu_mail ]
then
MAILST=`/bin/cat /usr/local/etc/rmu_mail`
fi

if  [ X"$1" = X"-r" ]
then
REMOVE=T
shift
fi

SFY=0

if  [ X"$1" != X"" ]
then
OP_MO=$1
shift
else
if  [ $MM -eq 1 ]
then
OP_MO=12
SFY=1
else
OP_MO=`expr $MM - 1`
fi
fi
if  [ $OP_MO -lt 10 ]
then
OP_MO=0${OP_MO}
fi

if  [ X"$1" != X"" ]
then
OP_YR=$1
else
OP_YR=`expr $YY - $SFY`
fi

#
# Input file name
IFN=$LOGDIR/M.${OP_YR}.${OP_MO}
if  [ ! -f $IFN ]
then
/usr/ucb/mail -s \""Uptime Report from $MYHSTNM"\" $MAILST << EOF
File $IFN did not exist as of `date`;
no report available.
EOF
exit 1
fi

#
# Run report program.
$BINDIR/rst < $IFN > /tmp/$$.rmu

#
# Mail results.
MYHSTNM=`/bin/hostname`
/usr/ucb/mail -s \""Uptime Report from $MYHSTNM"\" $MAILST << EOF
`/bin/cat /tmp/$$.rmu`
EOF

#
# End.
if  [ X"$REMOVE" = X"T" ]
then
$RM -f $LOGDIR/D.${OP_YR}.${OP_MO}.*.Y
fi
rm -f /tmp/$$.rmu
exit 0