Cover V06, I06
Article
Listing 1

jun97.tar


Listing 1: Create report of su activity

#!/bin/sh
#######################################################
# This script creates a user specific report of su
# activity.
# The output for the report is located in the user's
# home directory.
#
#     Activity Notes:
#  08-10-95  Created.   CConner
#######################################################
REPORTOUT="$HOME/sulog.`date +%m%d%y`.`date +%I%M%p`"
export REPORTOUT

echo "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
echo "X                                              X"
echo "X Indicate the year to use for the su report:  X"
echo "X   Press enter for the current year.          X"
echo "X   Enter the year for other years (i.e. 1994).X"
echo "X                                              X"
echo "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
echo "enter number for other than current year:"
read year

while [ 0 ]
do

if [ -n "$year" -a "$year" != `date +%Y` ]
then
SUYEAR="$year"
suyear="$year"

if [ ! -f "/var/adm/sulog$suyear" ]
then
echo "No data for $suyear."
echo "Please select another year."
read year
else
break
fi
else
SUYEAR=`date +%Y`
suyear=""
break
fi

done

export suyear SUYEAR

echo "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
echo "X                                              X"
echo "X Enter the type of SU attempts:               X"
echo "X         Enter 1 for Successful attempts.     X"
echo "X         Enter 2 for UnSuccessful attempts.   X"
echo "X         Enter all for all SU attempts.       X"
echo "X                                              X"
echo "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
echo "enter number or all:"
read sutype

while [ 0 ]
do
if  [ "$sutype" = "1" ]
then
SUTYPE="+"
SUTITLE="S U C C E S S F U L"
break
else
if [ "$sutype" = "2" ]
then
SUTYPE="-"
SUTITLE="U N S U C C E S S F U L"
break
else
if [ "$sutype" = "all" ]
then
SUTYPE=""
SUTITLE="A L L"
break
else
echo "\nPlease enter number."
read sutype
fi
fi
fi
done
export sutype SUTYPE SUTITLE

echo "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
echo "X                                              X"
echo "X Enter the month in numerics                  X"
echo "X      (i.e. January is 1, December is 12).    X"
echo "X Enter all for the entire year.               X"
echo "X                                              X"
echo "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
echo "enter number or all:"
read month

while [ -z "$month" ]
do
echo "\nPlease enter number or all."
read month
done

case "$month"
in
1) SELMONTH="J A N U A R Y";;
2) SELMONTH="F E B R U A R Y";;
3) SELMONTH="M A R C H";;
4) SELMONTH="A P R I L";;
5) SELMONTH="M A Y";;
6) SELMONTH="J U N E";;
7) SELMONTH="J U L Y";;
8) SELMONTH="A U G U S T";;
9) SELMONTH="S E P T E M B E R";;
10) SELMONTH="O C T O B E R";;
11) SELMONTH="N O V E M B E R";;
12) SELMONTH="D E C E M B E R";;
all) SELMONTH="F O R  T H E  Y E A R  O F";;
*)  echo "Please enter a valid month."
exit 1;;
esac

# Print report Header

echo "Your report is located in $REPORTOUT"

echo "`date +%D`" > $REPORTOUT
echo "\nMachine: `hostname`" >> $REPORTOUT
echo "\n$SUTITLE  S U  A T T E M P T S" >> $REPORTOUT
echo "           $SELMONTH  $SUYEAR \n" >> $REPORTOUT
if [ "$sutype" != "all" ]
then

echo "Date      Time       User Id     SU to \n" \
>> $REPORTOUT
fi

Nodata () {

echo "\n\nNo data matching criteria."   >> $REPORTOUT

}

# Print entire year with no edits for sutype

if [ "$month" = "all"  -a "$sutype" = "all" ]
then

if [ -s "/var/adm/sulog$suyear" ]
then
cat "/var/adm/sulog$suyear" >> $REPORTOUT
else
Nodata
fi

exit 1

fi

# Print entire year with edits for sutype

if [ "$month" = "all" -a "$sutype" != "all" ]
then

if [ `grep " $SUTYPE " "/var/adm/sulog$suyear"  |
wc -l` -eq "0" ]
then
Nodata
else

cat "/var/adm/sulog$suyear"                     |
grep " $SUTYPE "                                |
cut -d" " -f2,3,6                               |
sed "s/-/ /g"                                   |
awk ' $3 !~ /root/ { print $1, $2, $3, $4 } '   |
sort +2 -2.4                                    |
sed "s/ /       /g" >> $REPORTOUT

fi

exit 1

fi

if [ "$month" > "9" ]
then
EDMON="$month\/"
else
EDMON="0$month\/"
fi

export EDMON

# Print selected month with edits for sutype

if [ "$month" != "all"  -a "$sutype" != "all" ]
then

if [ `grep " $SUTYPE " "/var/adm/sulog$suyear"  |
grep "$EDMON" | wc -l` -eq "0" ]
then
Nodata
else

cat "/var/adm/sulog$suyear"                       |
grep " $SUTYPE "                                  |
cut -d" " -f2,3,6                                 |
sed "s/-/ /g"                                     |
awk ' $3 !~ /root/ { print $1, $2, $3, $4 } '     |
grep $EDMON                                       |
sort +2 -2.4                                      |
sed "s/ /       /g" >> $REPORTOUT

fi

exit 1

fi

# Print selected month with no edits for sutype

if [ "$month" != "all"  -a "$sutype" = "all" ]
then


if [ `grep "$EDMON" "/var/adm/sulog$suyear"       |
wc -l` -eq "0" ]
then
Nodata
else

cat "/var/adm/sulog$suyear"                       |
grep $EDMON >> $REPORTOUT

fi

fi


# End of File