Listing 1: PatchReporter
#!/bin/ksh
# Patch Reporter
PATH="/usr/bin:/bin:/sbin" ; export PATH
############## Config ######################
MAIL_LIST="joe@foobar.com"
MACHINES="SUN_MACHINES"
PATCHDATA="patch_data" # Disposable Directory
INFO="patch_info"
TMPOUT="patchout"
TEMP1="patchtmp"
FINISH="patchout.fin"
############################################
clean_tmp()
{
if [ -s $TMPOUT ]
then
rm $TMPOUT
fi
if [ -s $FINISH ]
then
rm $FINISH
fi
if [ -s $TEMP1 ]
then
rm $TEMP1
fi
if [ -d $PATCHDATA ]
then
cd $PATCHDATA
rm -f *
fi
}
verify_config()
{
if [ ! -f $MACHINES ]
then
print "Server listing(s) file cannot be found !!!"
exit
fi
if [ ! -f $INFO ]
then
print "Patch descriptions cannot be found !!!"
exit
fi
if [ ! -d $PATCHDATA ]
then
print "Creating patch data directory"
mkdir -p $PATCHDATA
fi
}
main()
{
for machines in $( < $MACHINES ) ; do
/bin/rsh -n $machines "showrev -p | awk '{print $2}'" > \
$PATCHDATA/$machines
done
for machines in `ls $PATCHDATA` ; do
for patches in `/bin/cat $INFO | awk '{print $1}'` ; do
for des in `/bin/cat $INFO | grep $patches | awk '{print $2'}` ; do
PATCH=`/bin/grep $patches $PATCHDATA/$machines\
| awk '{print $2}' | tail -1` < /dev/null
PATCH=${PATCH:="Not-Installed"}
printf "%-10s\t %-15s\t %-21s\t %s \n" $machines $PATCH\
$des $patches >> $TMPOUT
done;done;done
}
send_report()
{
printf "%-10s\t %-15s\t %-21s\t %s \n" Hostname Installed\
Description Patch > $TEMP1
/bin/sort +3 $TMPOUT >> $TEMP1
cat $TEMP1 | sed -e '/^$/d' | sed '/Patch/a\
' > $FINISH
cat $FINISH | mailx -s "Solaris Patch Report" $MAIL_LIST
}
#
# Function List
#
clean_tmp
verify_config
main
send_report
clean_tmp
# End of File
|