Configuration Tracking
Robert Ess
What is this machine's IP address? How much disk does
it have? How much
swap space? Has the configuration changed lately? These
are typical
questions you and others probably often ask about your
installed base of
UNIX workstations. The shell script, sys.conf, shown
in Listing 1 is a
very simplistic approach toward maintaining a flat file
database of all
your installed workstations. If configured into the
bootup sequence, the
script can notify you when a machine comes online for
the first time and
will let you know when the hardware or software configuration
for that
machine changes. Figure 1 shows a sample output from
sys.conf from an
HP9000, Model 725 running HP-UX.
How does it work?
The sys.conf script is a series of simple shell functions,
and making
the script functional on several platforms required
some ugly case
statements. This script could probably have been written
in 30 lines of
Perl or less, but since I don't know Perl, I wrote it
as a Bourne shell
script with shell functions. This also allowed for greater
portability.
The script first checks to see that the user running
the script is root;
it then divines the operating system that the script
is running on. Each
OS has something different about it, such as the Ethernet
interface
name, the swap command, or arguments to the mail command,
so the first
case construct in the Define_Vars shell function is
used to build those
commands with the appropriate syntax.
To determine the machine's hardware serial number from
a script, I
created a file in /usr/tmp, host_name.sn, in which host_name
is the
actual hostname of that machine. In the Machine_Data
shell function, you
will need to insert your own server's host names to
preclude any user
being reported as the logged in id. For example,
Machine_Data(){
MACHINE='uname -m'
OSREV='uname -r'
case 'hostname' in
serv01|serv02|serv03) LASTLOGIN="Server";;
*) LASTLOGIN='$PSCMD | egrep -v "lp|daemon|root|UID" | \
awk '{print $1}' | head -1';;
esac
I use three different methods to try to obtain the primary
user for a
machine. The first method involves checking the process
table for the
first nonsystem user. If no one is logged in at the
time the script is
run, it uses the last utility to check /etc/wtmp for
the last non-root
console login. If this is unsuccessful, the script checks
the existing
baseline file from previous runs to see whether a user
name has been
captured. If none of these is successful, LASTLOGIN
is set to Unknown.
Next, the Network_Data function is called. The operation
of this
function is straightforward. It reports the number of
Ethernet
interfaces, their IP addresses, the netmask and broadcast
values, and
the default router. These are all trivial to obtain,
but are nicely
contained in one shell function.
In Disk_Data, vendor-specific commands are used to report
on the locally
attached disks. HP-UX, Solaris, and SunOS all use different
commands to
report on device and filesystem swap.
There are also shell functions for each of the operating
systems that
allow you to tailor the output to your liking. HP has
the handy ioscan
command for scanning the hardware bus. Also, the installed
fileset
information is easily perused and grepped. In HP-UX
10.x, the swlist
utility provides a very informative list of installed
products for a
machine. Solaris uses the showrev -p command to list
installed patches,
and I use the output of pkginfo for product information.
Implementation
Ideally, sys.conf should reside on an NFS-mounted filesystem
accessible
by all of your workstations. I put ours on an Auspex
file server, and
have a single file that is called by all of the workstations
through
cron. Thus, I can easily make changes to all of the
workstations at one
time.
If you want to put this script into your machine's startup
sequence, I
suggest the localrc function in HP-UX 9.x and /etc/rc2.d/S99sysconf
as
the last startup script called in Solaris. When the
script is run for
the very first time, it checks for /usr/tmp/'hostname'.bl.
If it is not
found, the script assumes this to be a new install,
and mail is sent to
$ADMIN.
Each night via cron, the script is run, and the resulting
output file is
diffed against the baseline file, /usr/tmp/'hostname'.bl.
If any
differences are found, they are mailed to the $ADMIN,
informing him/her
of any changes taken place on the machine since the
previous night's
run. The previous configuration is then moved to a timestamped
file,
which provides a history of the machine's configuration.
I use a trusted host to rcp all of the baseline files
to a common
repository on our Auspex server. Then, I write a simple
script that will
display the desired system's configuration.
So, when the boss walks in and says, "I need a
count of all the SPARC
20s with 500 Mb or more of disk, 64 Mb or more of RAM,
how many HP 725s
we have with less than 400 Mb, and who owns that HP-UX
10.01 box out in
Bloomfield. Oh, by the way, I need it in 15 minutes,"
I don't panic. I
run my script, give him a printout, and go fight the
next fire.
About the Author
Bob Ess has been in the computing business long enough
to know better.
He is currently a senior UNIX systems administrator
at DSC Communication
Corporation in Plano, Texas. He can be reached at ress@spd.dsccc.com
|