Cover V05, I09
Article
Figure 1
Listing 1

sep96.tar


Listing 1: sys.conf

#!/bin/sh


# $Header: sys.conf,v 1.10 96/05/20 13:34:29 ress Exp $
# $Author: ress $
# $Revision: 1.10 $

#
# Usage
#
Usage(){
echo "Usage: sys.conf [-print] [-screen]"
exit 0
}

#
# Parse the command line args
#
while [ $# -ne 0 ];
do
case $1 in
-print)		PRINT=1;;
-screen)	SCREEN=1;;
-h*)		Usage;;
*)		:;;
esac
shift
done

# ==========================================================
#                     BEGIN FUNCTION DEFINITIONS
# ==========================================================
#
# Are we root?
#
Check_User(){
UID=`id | cut -d'(' -f1 | cut -d'=' -f2`
if [ $UID -ne 0 ]; then
echo "You must be root to run $0."
exit 1
fi
return
}

#
# Determine system type
#
Get_Arch(){
ARCH=`uname -r`
case $ARCH in
A.09.*) 	SYSTYPE=HPUX09;;
B.10.*) 	SYSTYPE=HPUX10;;
5.[1-5])    	SYSTYPE=Solaris;;
4.1.[1-3]*)	SYSTYPE=SunOS;;
*)		echo "System type unsupported"
exit 1;;
esac
return
}

#
# Setup variables for system specific syntax of common commands
#
Define_Vars(){
case $SYSTYPE in

HPUX*)	PATH=/bin:/usr/bin:/sbin:/usr/sbin:/etc
SWAPFILE=`swapinfo | egrep "dsk|lvol" | awk '{print $9}'`
DEVSWAP=`swapinfo | grep dev | awk '{print $2}'`
FILESWAP=`swapinfo | grep fs | awk '{print $2}'`
MACADDR=`lanscan | grep x | awk '{print $2}'`
MODEL=`model`
MEMORY=`dmesg | grep Phys | awk '{print $2}'`K
DISKCMD='bdf -t hfs'
CCOMP=`what /bin/cc | grep HP | cut -d' ' -f2`
ETHERIF=lan0
MAILCMD=mailx
PRTCMD=lp
PSCMD='ps -ef';;

Solar*)	PATH=/bin:/sbin:/usr/sbin:/usr/ucb
PATH=$PATH:/usr/ccs/bin:/usr/bin
SWAPFILE=`swap -l | grep dsk | awk '{print $1}'`
DEVSWAP=`swap -l | grep dsk | awk '{print $4}'`
MACADDR=`dmesg | grep Ether | tail -1 | awk '{print $4}'`
MODEL=`prtconf | egrep "SPARC|4_"`
MEMORY=`dmesg | grep '^mem' | tail -1 | awk '{print $3}'`
DISKCMD='df -tkFufs'
CCOMP=`what /usr/ucb/cc | grep SMI | awk '{print $2}'`
ETHERIF=le0
MAILCMD=mailx
PRTCMD=lp
PSCMD='ps -ef';;

SunOS)	PATH=/bin:/usr/ucb:/etc:/usr/etc
SWAPFILE='/dev/'`dmesg | grep swap | tail -1 | awk '{print $3}'`
DEVSWAP=`pstat -T | grep swap | awk '{print $1}' \
| cut -d'/' -f2`
MACADDR=`ifconfig -a | grep ether | tail -1 | awk '{print $2}'`
MODEL=`dmesg | egrep "LX|SPARC|4/75|4/50"| tail -1 \
| awk '{print $3, $4}'`
MEMORY=`dmesg | grep '^mem' | tail -1 | awk '{print $3}'`
DISKCMD='df -t 4.2'
CCOMP="Unknown"
ETHERIF=le0
MAILCMD=/usr/openwin/bin/mail
PRTCMD=lpr
PSCMD='ps aux';;

esac

ADMIN="youremailaddr"
MAILFILE=/usr/tmp/`hostname`.mf
TIMESTAMP=`date +%m%d%y`
if [ ! -f /usr/tmp/`hostname`.bl ];then
OUTFILE=/usr/tmp/`hostname`.bl
NEW=1
else
OUTFILE=/usr/tmp/`hostname`
if [ -f $OUTFILE ]; then
/bin/rm $OUTFILE
fi
fi

SNFILE=/usr/tmp/`hostname`.sn
if [ -f $SNFILE ]; then
SERIALNO=`cat $SNFILE`
else
SERIALNO="Unknown"
fi

return
}

#
# To keep from identifying server machines as
# belonging to an individual, the 'case' statement
# makes a check and changes LASTLOGIN to "Server"
# Otherwise, check the first non-root|daemon|lp|UID
# user of the box. Not failsafe, but as close as
# I can get.
#
Machine_Data(){
MACHINE=`uname -m`
OSREV=`uname -r`

case `hostname` in
serv01|serv02|serv03) 		LASTLOGIN="Server";;
*) LASTLOGIN=`$PSCMD | egrep -v "lp|daemon|root|UID|bin|USER" | \
awk '{print $1}' | head -1`;;
esac

#
# If no one is logged in, check wtmp
#
if [ -z "$LASTLOGIN" ]; then
LASTLOGIN=`last | grep console | \
grep -v "root" | head -1 | awk '{print $1}'`
fi

#
# If that fails, see if we have recorded it before
#
if [ -z "$LASTLOGIN" ]; then
LASTLOGIN=`grep Login /usr/tmp/*.bl | awk '{print $4}'`
fi

#
# Alas, we are clueless...
#
if [ -z "$LASTLOGIN" ]; then
LASTLOGIN="Unknown.."
fi

cat >> $OUTFILE << __EOF__
=======================================
System Configuration report for `hostname`
=======================================

Machine data
============
Machine              :  $MACHINE
Serial number        :  $SERIALNO
Model                :  $MODEL
O.S. revision        :  $OSREV
C Compiler revision  :  $CCOMP
Memory               :  $MEMORY
Last Login           :  $LASTLOGIN

__EOF__
return
}

#
# NetworkData
#
Network_Data(){
NOETHERIF=`netstat -in | egrep -v "lo0|ni|Address" | wc -l`
IPADDR=`ifconfig $ETHERIF | grep inet | awk '{print $2}'`
NETMASK=`ifconfig $ETHERIF | grep inet | awk '{print $4}'`
BROADCAST=`ifconfig $ETHERIF | grep broad | awk '{print $6}'`
NETMASKCK="255.255.255.0"
BROADCASTCK="255"
DEFROUTER=`netstat -rn | grep default | awk '{print $2}'`

$PSCMD | grep ypbind | grep -v grep > /dev/null
if [ $? = 0 ]; then
YPCLIENT="True"
else
YPCLIENT="False"
fi

$PSCMD | grep ypserv | grep -v grep > /dev/null
if [ $? = 0 ]; then
YPSERVER="True"
else
YPSERVER="False"
fi

echo "Network data" >> $OUTFILE
echo "============" >> $OUTFILE
echo "NIS domain           : " `domainname` >> $OUTFILE
echo "NIS client           : " $YPCLIENT >> $OUTFILE
echo "NIS server           : " $YPSERVER >> $OUTFILE
echo "" >> $OUTFILE
echo "ethernet interfaces  : " $NOETHERIF
>> $OUTFILE

if [ $NOETHERIF -gt 1 ]; then

echo "Name    Address       Broadcast       Netmask"  >> $OUTFILE
echo "=============================================" >> $OUTFILE

netstat -i | egrep -v "lo0|ni|Queue" > /tmp/$$
exec < /tmp/$$
while [ 1 ];
do
read line
RC=$?
if [ $RC != 0 ]; then
break
fi
IFNAME=`echo $line | awk '{print $1}'`
IFHOST=`echo $line | awk '{print $4}'`
IFIPAD=`grep " $IFHOST " /etc/hosts | awk '{print $1}'`
IFMSK=`ifconfig $IFNAME | grep inet | awk '{print $4}'`
IFBRD=`ifconfig $IFNAME | grep inet | awk '{print $6}'`
echo $IFNAME $IFIPAD $IFBRD $IFMSK | \
awk '{printf"%-5s %-15s %-15s %-15s\n",$1,$2,$3,$4}' >> $OUTFILE
done
rm /tmp/$$
else
echo "IP Address           : " $IPADDR >> $OUTFILE
echo "MAC Address          : " $MACADDR >> $OUTFILE
echo "Netmask              : " $NETMASK >> $OUTFILE
echo "Broadcast            : " $BROADCAST >> $OUTFILE
echo "Default router       : " $DEFROUTER >> $OUTFILE
fi
echo "" >> $OUTFILE
return
}

#
# DiskData
#
Disk_Data(){
echo "Disk data:" >> $OUTFILE
echo "===========================================================" >>
$OUTFILE

echo "Device_file" "Partition_Size" "Mount_Point" | \
awk '{printf"%-20s %-20s %-20s\n", $1,$2,$3}' >> $OUTFILE

echo "===========================================================" >>
$OUTFILE

#
# Setup a special case for Journal File Systems at HP-UX 10.10
#
case $SYSTYPE in
HPUX10)	bdf -t hfs | grep -v Mounted | \
awk '{printf"%-20s %-20d %-20s\n", $1,$2,$6}' >> $OUTFILE
bdf -t vxfs | grep -v Mounted | \
awk '{printf"%-20s %-20d %-20s\n", $1,$2,$6}' >> $OUTFILE;;
*)	$DISKCMD | grep -v Mounted | \
awk '{printf"%-20s %-20d %-20s\n", $1,$2,$6}' >> $OUTFILE
esac

case $SYSTYPE in
HPUX*) swapinfo | grep dev |
while [ 1 ];
do
read line
RC=$?
if [ $RC != 0 ]; then
break
fi
SWAPFILE=`echo $line | egrep "dsk|lvol" | awk '{print $9}'`
DEVSWAP=`echo $line | grep dev | awk '{print $2}'`
echo $SWAPFILE $DEVSWAP "swap" | \
awk '{printf"%-20s %-20s %-20s\n", $1,$2,$3}' >> $OUTFILE
done;;

Solar*) swap -l | grep -v swapfile |
while [ 1 ];
do
read line
RC=$?
if [ $RC != 0 ]; then
break
fi
SWAPFILE=`echo $line| grep dsk| awk '{print $1}'`
DEVSWAP=`echo $line | grep dev| awk '{print $4}'`
echo $SWAPFILE $DEVSWAP "swap" | \
awk '{printf"%-20s %-20s %-20s\n", $1,$2,$3}' >> $OUTFILE
done;;

SunOS) 	echo $SWAPFILE $DEVSWAP "swap" | \
awk '{printf"%-20s %-20s %-20s\n", $1,$2,$3}' >> $OUTFILE;;

*);;
esac
return
}

#
# HPUX09_Func
#
HPUX09_Func(){
cat >> $OUTFILE << __EOF__

IOSCAN output data
==================
__EOF__

/etc/ioscan -f -b >> $OUTFILE

cat >> $OUTFILE << __EOF__

Patch Data
==============================
Name     :  Index Description
==============================
__EOF__

cd /system
for PATCH in `ls -1d PH*`
do
DESC=`grep "fd:" $PATCH/index | cut -d':' -f2`
echo $PATCH ":" $DESC >> $OUTFILE
done

cat >> $OUTFILE << __EOF__

==================================================
Installed printers (from lpstat)
==================================================

__EOF__

lpstat -a | grep "accepting" | sort | uniq | awk '{print $1}' >> $OUTFILE

cat >> $OUTFILE << __EOF__

==================================================
Installed filesets (from /etc/filesets)
==================================================
__EOF__
ls -C /etc/filesets >> $OUTFILE

echo >> $OUTFILE
return
}

#
# HPUX10_Func
#
HPUX10_Func(){
cat >> $OUTFILE << __EOF__

IOSCAN output data
==================
__EOF__

/etc/ioscan -f >> $OUTFILE

cat >> $OUTFILE << __EOF__

=================================================
Installed printers (from lpstat)
=================================================

__EOF__

lpstat -a | grep "accepting" | sort | uniq | awk '{print $1}' >> $OUTFILE

cat >> $OUTFILE << __EOF__

==================================================
Installed filesets (from swlist -l product )
==================================================
__EOF__
swlist -x one_liner="name revision title" -l product | \
grep -v "#" | cut -c1-60 >> $OUTFILE

return
}


#
# SOLARIS_Func
#
SOLARIS_Func(){
cat >> $OUTFILE << __EOF__

==================================================
Installed patches (from 'showrev -p')
==================================================
__EOF__

showrev -p | awk '{print $2}' >> $OUTFILE

cat >> $OUTFILE << __EOF__

==================================================
Installed printers (from lpstat)
==================================================
__EOF__

lpstat -a | grep "accepting" | sort | uniq | awk '{print $1}' >> $OUTFILE

cat >> $OUTFILE << __EOF__

==================================================
Installed packages (from pkginfo)
==================================================
__EOF__

pkginfo >> $OUTFILE
return
}

#
# SUNOS_Func
#
SUNOS_Func() {
cat >> $OUTFILE << __EOF__

==================================================
Installed printers (from lpc stat)
==================================================
__EOF__

lpc stat | grep : | cut -d':' -f1 >> $OUTFILE
return
}

NotifyAdmin() {
if [ -f /usr/tmp/`hostname` -a -f /usr/tmp/`hostname`.bl ]; then
diff /usr/tmp/`hostname`.bl /usr/tmp/`hostname` > /dev/null
if [ $? = 1 ]; then
echo >> $MAILFILE
echo "Configuration differences since last run:" >> $MAILFILE
diff /usr/tmp/`hostname`.bl /usr/tmp/`hostname` >> $MAILFILE

# If there is a difference, we now move old
# baseline and timestamp it. Move config to baseline
/bin/mv /usr/tmp/`hostname`.bl /usr/tmp/`hostname`.bl.$TIMESTAMP
/bin/mv /usr/tmp/`hostname` /usr/tmp/`hostname`.bl

fi
fi

#
# If the configuration has changed, notify the admin
#
if [ -f $MAILFILE ]; then
$MAILCMD -s "`hostname`_status" $ADMIN < $MAILFILE
/bin/rm $MAILFILE
fi

#
# If this is the first instance of the .bl file being
# created, notify the admin that it is online
#
if [ $NEW ]; then
$MAILCMD -s "`hostname`_online" $ADMIN < $OUTFILE
fi

#
# Display to screen?
#
if [ $SCREEN ]; then
more $OUTFILE
fi

#
# Print it out?
#
if [ $PRINT ]; then
$PRTCMD $OUTFILE
fi

return
}

# ============================================================
#                     END OF FUNCTION DEFINITIONS
# ============================================================
#
# system-independent functions
#
Check_User
Get_Arch
Define_Vars
Machine_Data
Network_Data
Disk_Data

#
# system-dependent functions
#
case $SYSTYPE in
HPUX09)		HPUX09_Func;;
HPUX10)		HPUX10_Func;;
Solaris)	SOLARIS_Func;;
SunOS)		SUNOS_Func;;
*)		;;
esac

NotifyAdmin

# End of File