1 #!/bin/sh -- # -*- shell-script -*-
3 # SysAudit/SysConfig -- Capture UNIX machine information
4 # Copyright (C) 1997 David J. Young <davidy@pencom.com>
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 # Modification History
24 # 1.0 ??-???-96 Robert Ess <ress@spdmail.spd.dsccc.com> - Created.
25 # 2.0 15-Aug-96 David J. Young <davidy@psa.pencom.com> - Modified.
26 # Added/modified code in the Solaris section:
27 # - Extracted IP address, MacAddr, C compiler and other information
28 # from more reliable sources.
29 # - Added dump of information for the Veritas Volume Manager.
30 # - Calculate and report total swap space
31 # - Report if the machine is acting as a NFS and/or NIS Server or Client
32 # - Added counters for number of patches, printers and packages
33 # - Fix a small bug you had with the previous file (*.bl).
34 # 3.0 4-Sep-96 David E. Nelson <dnelson@psa.pencom.com> - Modified.
35 # Added/modified code in the SunOS section:
36 # - Added code operate in either an "audit" or "check" mode.
37 # - Added SWAPSPACE and KERNEL info.
38 # - Also added MACADDR, since you must be root to obtain this info using ifconfig.
39 # - Made sure the script would work on an Auspex
40 # 3.1 10-Sep-96 David J. Young <davidy@psa.pencom.com> - Modified.
41 # Added/modified code to complete the HPUX section.
42 # Added Modification History and Description.
44 # 3.2 12-Sep-96 David E. Nelson <dnelson@psa.pencom.com> - Modified.
45 # The vast majority of the changed/additons are for SunOS 4.1.x/3.5 and
47 # Added support for SunOs 3.5. Yes, 3.5! That's NOT a typo!
48 # Modified Auspex and added auspex specific commands
49 # Added Notification of vars that didn't get set.
50 # Added exported filesystems in output.
51 # Fixed bug in SysConfig|SysAudit name determination.
52 # Added gated detection.
53 # 3.3 10-Oct-96 David E. Nelson <dnelson@psa.pencom.com> - Modified.
54 # Added support for Solaris 2.5.1
55 # 3.4 09-Jan-97 David J. Young <davidy@Psa.pencom.com> - Modified.
56 # Fixed small problems when running on HP-UX.
59 # The original philosophy of the script that Robert Ess wrote was to run
60 # every day as a cron job. If there were *any* machine configuration
61 # changes, those changes (differences) would be mailed back to the
62 # administrator to make him aware that something changed.
64 # David Young took the original script and modified it to perform a
65 # "snapshot" report of a system it was run on. His goal at the time was
66 # to perform an audit and needed a report that was a "baseline" for each
67 # system he ran it on. The script was modified to collect as much
68 # information about the machine as possible.
70 # These two goals were then merged by David J. Young & David E. Nelson.
71 # Small changes here and there made it so that the script can perform
72 # either function. This file should be name "SysAudit" or "SysConfig".
73 # If the name is SysConfig, it can be run out of cron and will send
74 # E-mail to "SysConfigReport". If the script is called SysAudit, it will
75 # collect information and send it to standard output as a report.
77 # Most sites will problably want to hard link SysConfig and SysAudit, so
78 # that the script can be executed either way.
85 echo "Usage: SysConfig|SysAudit"
86 echo " SysConfig: Generates system info that is static."
87 echo " SysAudit: Generates system info that is dynamic."
92 # Parse the command line args
94 NOPRINTER=0; export NOPRINTER
95 NOPATCHES=0; export NOPATCHES
96 NOPKGS=0; export NOPKGS
97 TMPFILE=/tmp/SysAudit.$$
98 trap 'rm -f $TMPFILE 2>/dev/null' EXIT
118 # =============================================================================
119 # BEGIN FUNCTION DEFINITIONS
120 # =============================================================================
128 *SysConfig) AUDIT=0;;
129 *) AUDIT=1;; # The default behavior is to do an audit.
138 UID=`id | cut -d'(' -f1 | cut -d'=' -f2`
139 if [ "$UID" -ne "0" ]; then
141 echo "***************************************************"
142 echo "** WARNING: You are not root. **"
143 echo "** Running as root will give you better results. **"
144 # echo "** Especially for the remark command: rm -rf .* **"
145 echo "***************************************************"
158 # Determine system type
162 if [ -f /bin/arch ]; then
163 if [ `/bin/arch -k` = "sun3" ]; then
173 HP-UX) REV=`uname -r|cut -d. -f2`
174 if [ $REV = "09" ]; then
176 elif [ $REV = "10" ]; then
180 SunOS) REV=`uname -r|cut -d. -f1`
181 if [ $REV = 5 ]; then
183 elif [ $REV = 4 ]; then
187 sun3) SYSTYPE=SunOS3;;
189 IRIX) REV=`uname -r|cut -d. -f1`
190 if [ $REV = 6 ]; then
192 elif [ $REV = 5 ]; then
196 *) echo "System type unsupported"
203 # Setup variables for system specific syntax of common commands
211 HPUX*) PATH=/bin:/usr/bin:/sbin:/usr/sbin:/etc
212 if [ $NOTROOT -eq "0" ]; then
213 SWAPFILE=`swapinfo | egrep "dsk|lvol" | awk '{print $9}'`
214 DEVSWAP=`swapinfo | grep dev | awk '{print $2}'`
215 FILESWAP=`swapinfo | grep fs | awk '{print $2}'`
216 SWAPSPACE=`swapinfo -t | grep tot | awk '{print $2}'`
218 SWAPFILE="<Must run swapinfo(1) as root>"
223 MACADDR=`lanscan | grep x | awk '{print $2}'`
227 MEMORY=`dmesg | grep Phys | awk '{print $2}'`K
228 if [ $MEMORY = 'K' ]; then
229 if [ $NOTROOT -eq "1" ]; then
230 MEMORY="<Must be root to read /dev/mem>"
236 CCOMP=`what /bin/cc | grep HP | cut -d' ' -f2`
243 Solar*) PATH=/bin:/sbin:/usr/sbin:/usr/ucb
244 PATH=$PATH:/usr/ccs/bin:/usr/bin
245 SWAPFILE=`swap -l | grep dsk | awk '{print $1}'`
246 DEVSWAP=`swap -l | grep dsk | awk '{print $4}'`
247 MODEL=`prtconf -vp | grep banner-name | awk -F\' '{print $2}'`
248 # MEMORY=`dmesg | grep '^mem' | tail -1 | awk '{print $3}'` #'
249 MEMORY=`prtconf | grep '^Memory size' | sed 's/Memory size: //'`
250 KERNEL=`sysdef | grep Generic | awk '{print $1}'`
253 EXPORTFS='showmount -e '$HOSTNAME
254 HOSTID=`sysdef -h | tail -1 | awk '{print $1}'`
255 if [ -x /usr/ccs/bin/what ]; then
256 if [ -d /opt/SUNWspro ]; then
257 CCOMP=`what /opt/SUNWspro/bin/cc | grep RELEASE | \
258 sed 's/.*RELEASE VERSION //'`
260 CCOMP=`what /usr/ucb/cc | grep SMI | awk '{print $2}'`
261 CCOMP="$CCOMP (bundled)"
264 CCOMP="<No Compiler>"
267 ETHERIF=`ifconfig -a|grep BROADCAST | awk -F: '{print $1}'| head -1 `
268 IPADDR=`ifconfig $ETHERIF | grep inet | awk '{print $2}'`
269 # MACADDR=`dmesg | grep Ether | tail -1 | awk '{print $4}'`
270 # MACADDR=`arp -a | grep $HOSTNAME | sed 's/.*\(08:00.*\) .*/\1/'`
271 MACADDR=`arp $IPADDR | awk '{print $4}'`
275 SWAPSPACE=`swap -s | awk '
279 swapusedlen = length(swapused) - 1
280 swapavailen = length(swapavail) - 1
281 usedk = substr(swapused,1,swapusedlen)
282 availk = substr(swapavail,1,swapavailen)
283 total = (availk + usedk)/1000
284 printf("%2.0f Megabytes\n", total)
288 SunOS) PATH=/bin:/usr/bin:/usr/ucb:/etc:/usr/etc
289 SWAPFILE='/dev/'`dmesg | grep swap | tail -1 | awk '{print $3}'`
290 DEVSWAP=`pstat -T | grep swap | awk '{print $1}' \
293 if [ `arch -k` = "aushp" ]; then
300 if [ "$NOTROOT" = "1" ]; then
301 MACADDR=`dmesg | grep -i "ethernet address" | awk '{ print $4 }' | tail -1`
303 MACADDR=`ifconfig $ETHERIF | grep ether | tail -1 | awk '{print $2}'`
305 if [ -z "$MACADDR" ]; then
306 MACADDR="Root access required."
309 MODEL=`dmesg | egrep "LX|SPARC|4/75|4/50"| tail -1 \
310 | awk '{print $3, $4}'`
312 if [ -z "$MODEL" ]; then
316 MEMORY=`dmesg | grep '^mem' | tail -1 | awk '{print $3}'`
318 if [ -z "$MEMORY" ]; then
327 SWAPSPACE=`pstat -T | grep "swap" | awk '{print $1}' | \
328 awk -F/ '{print $2}'`'K'
331 EXPORTFS='showmount -e '$HOSTNAME
334 SunOS3) PATH=/bin:/usr/bin:/usr/ucb:/etc:/usr/etc:/usr/5bin
335 SWAPFILE='/dev/'`dmesg | grep swap | tail -1 | awk '{print $3}'`
336 DEVSWAP=`pstat -T | grep swap | awk '{print $1}' \
338 if [ "$NOTROOT" = "1" ]; then
339 MACADDR=`dmesg | grep -i "ethernet address" | awk '{ print $4 }' | tail -1`
341 MACADDR=`ifconfig ie0 | grep ether | tail -1 | awk '{print $2}'`
344 if [ -z "$MACADDR" ]; then
345 MACADDR="Root access required."
348 MODEL=`dmesg | egrep "LX|SPARC|4/75|4/50"| tail -1 \
349 | awk '{print $3, $4}'`
351 if [ -z "$MODEL" ]; then
355 MEMORY=`dmesg | grep '^mem' | tail -1 | awk '{print $3}'`
357 if [ -z "$MEMORY" ]; then
367 SWAPSPACE=`pstat -T | grep "swap" | awk '{print $1}' | \
368 awk -F/ '{print $2}'`'K'
369 KERNEL=`strings /vmunix | grep UNIX | awk '{ print $7 }' | \
372 EXPORTFS='showmount -e '$HOSTNAME
376 UPTIME=`uptime | sed 's/.*\(up.*\)/\1/' | sed 's/\(.*user[s]*\),.*/\1/'`
377 LOADNOW=`uptime | sed 's/.*load average: \(.*\)/\1/'`
379 TIMESTAMP=`date +%m%d%y`
381 SNFILE=/usr/tmp/`hostname`.sn
382 if [ -f "$SNFILE" ]; then
383 SERIALNO=`cat $SNFILE`
393 # To keep from identifying server machines as
394 # belonging to an individual, the 'case' statement
395 # makes a check and changes LASTLOGIN to "Server"
396 # Otherwise, check the first non-root|daemon|lp|UID
397 # user of the box. Not failsafe, but as close as
406 serv01|serv02|serv03|serv04) LASTLOGIN="Server";;
407 *) LASTLOGIN=`$PSCMD | egrep -v "lp|daemon|root|UID" | \
408 awk '{print $1}' | head -1`;;
412 # If no one is logged in, check wtmp
414 if [ -z "$LASTLOGIN" ]; then
415 LASTLOGIN=`last | grep console | \
416 grep -v "root" | head -1 | awk '{print $1}'`
420 # If that fails, see if we have recorded it before
422 if [ -z "$LASTLOGIN" ]; then
423 LASTLOGIN=`grep Login /usr/tmp/*.bl | awk '{print $4}'`
427 # Alas, we are clueless...
429 if [ -z "$LASTLOGIN" ]; then
430 LASTLOGIN="Unknown.."
433 if [ "$AUDIT" -eq "1" ]; then
436 DATE="Dynamic parameter not reported."
437 UPTIME="Dynamic parameter not reported."
438 LOADNOW="Dynamic parameter not reported."
443 =======================================
444 System Configuration report for `hostname`
445 =======================================
455 Current load avg : $LOADNOW
457 Serial number : $SERIALNO
460 O.S. revision : $OSREV
462 C Compiler revision : $CCOMP
464 Swap space : $SWAPSPACE
465 Last Login : $LASTLOGIN
476 if [ "$AUSPEX" -eq "1" ]; then
477 NOETHERIF=`ax_netstat -i | egrep -v "127.0.0.1|Address|localhost|ni.\*" | \
478 wc | awk '{print $1}'`
480 NOETHERIF=`netstat -i | egrep -v "127.0.0.1|Address|localhost|ni.\*" | wc | \
484 if [ "$SYSTYPE" = "SunOS3" ]; then
485 IPADDR=`ifconfig $ETHERIF | awk '{print $2}'`
486 NETMASK=`ifconfig $ETHERIF | grep inet | awk '{print $4}'`
487 BROADCAST=`ifconfig $ETHERIF | grep broad | awk '{print $6}'`
488 NETMASKCK="255.255.255.0"
492 IPADDR=`ifconfig $ETHERIF | grep inet | awk '{print $2}'`
493 NETMASK=`ifconfig $ETHERIF | grep inet | awk '{print $4}'`
494 BROADCAST=`ifconfig $ETHERIF | grep broad | awk '{print $6}'`
495 NETMASKCK="255.255.255.0"
499 $PSCMD | egrep "routed|gated" | grep -v grep > /dev/null
500 if [ "$?" -eq "0" ]; then
501 DEFROUTER='<routed|gated running>'
503 DEFROUTER=`netstat -rn | grep default | awk '{print $2}'`
505 $PSCMD | grep ypbind | grep -v grep > /dev/null
506 if [ "$?" -eq "0" ]; then
512 $PSCMD | grep ypserv | grep -v grep > /dev/null
513 if [ "$?" -eq "0" ]; then
519 NFSMNTS=`$NFSFS | wc | awk '{print $1}'`
520 if [ "$NFSMNTS" -gt "0" ]; then
526 EXPORTCNT=`$EXPORTFS 2>&1 | grep -v RPC | wc | awk '{print $1}'`
527 if [ "$EXPORTCNT" -gt "0" ]; then
536 NIS domain : `domainname`
537 NIS client : $YPCLIENT
538 NIS server : $YPSERVER
540 NFS client : $NFSCLIENT
541 NFS server : $NFSSERVER
543 ethernet interfaces : $NOETHERIF
546 if [ "$NOETHERIF" -gt "1" ]; then
548 echo "Name Address Broadcast Netmask"
549 echo "============================================="
551 if [ `arch -k` = "aushp" ]; then
552 NSTATCMD='ax_netstat -i'
554 NSTATCMD='netstat -i'
557 eval $NSTATCMD | egrep -v "lo0|ni|Ipkts" | while read line
563 if [ "$IFHOST" = "none" ]; then
568 IFIPAD=`ifconfig $1 | grep inet | awk '{print $2}'`
569 IFMSK=`ifconfig $IFNAME | grep inet | awk '{print $4}'`
570 IFBRD=`ifconfig $IFNAME | grep inet | awk '{print $6}'`
573 [ -z "$IFIPAD" ] && IFIPAD="Unknown"
574 [ -z "$IFMSK" ] && IFMSK="Unknown"
575 [ -z "$IFBRD" ] && IFBRD="Unknown"
577 echo $IFNAME $IFIPAD $IFBRD $IFMSK | \
578 awk '{printf"%-6s %-15s %-15s %-15s\n",$1,$2,$3,$4}'
581 echo "IP Address : " $IPADDR
582 echo "MAC Address : " $MACADDR
583 echo "Netmask : " $NETMASK
584 echo "Broadcast : " $BROADCAST
585 echo "Default router : " $DEFROUTER
589 if [ "$NFSSERVER" = "True" ]; then
591 echo "============================================="
592 echo "Exported Filesystems"
593 echo "============================================="
609 echo "================================================================"
611 if [ "$AUDIT" -eq "1" ]; then
612 echo "Filesystem kbytes used avail capacity Mounted on"
614 echo "Device-File" "Cap." "Mount-Point" | \
615 awk '{printf"%-20s %35s %-20s\n", $1,$2,$3}'
618 echo "================================================================"
621 # Setup a special case for Journal File Systems at HP-UX 10.10
624 HPUX10) bdf -t hfs | grep -v Mounted | \
625 awk '{printf"%-40s %14d %-20s\n", $1,$2,$6}'
626 bdf -t vxfs | grep -v Mounted | \
627 awk '{printf"%-40s %14d %-20s\n", $1,$2,$6}';;
628 *) if [ "$AUDIT" = "1" ]; then
629 $DISKCMD | grep -v Mounted
631 $DISKCMD | grep -v Mounted | \
632 awk '{printf"%-40s %14d %-20s\n", $1,$2,$6}'
637 HPUX*) if [ $NOTROOT -eq 0 ]; then
638 swapinfo | grep dev | while [ 1 ]; do
641 if [ "$RC" != "0" ]; then
644 SWAPFILE=`echo $line | egrep "dsk|lvol" | awk '{print $9}'`
645 DEVSWAP=`echo $line | grep dev | awk '{print $2}'`
646 echo $SWAPFILE $DEVSWAP "swap" | \
647 awk '{printf"%-40s %14s %-20s\n", $1,$2,$3}'
650 SWAPFILE="<Must run swapinfo(1) as root>"
655 Solar*) swap -l | grep -v swapfile |
660 if [ "$RC" != "0" ]; then
663 SWAPFILE=`echo $line| grep dsk| awk '{print $1}'`
664 DEVSWAP=`echo $line | grep dev| awk '{print $4}'`
665 echo $SWAPFILE $DEVSWAP "swap" | \
666 awk '{printf"%-40s %14s %-20s\n", $1,$2,$3}'
669 SunOS*) echo $SWAPFILE $DEVSWAP "swap" | \
670 awk '{printf"%-40s %14s %-20s\n", $1,$2,$3}';;
688 patchnum=`ls -1d /system/PH* | wc -l`
693 ====================================================
694 $patchnum Installed patches (from /system/PH*/index)
695 ====================================================
700 for PATCH in `ls -1d PH* 2>/dev/null`; do
701 DESC=`grep "fd:" $PATCH/index | cut -d':' -f2`
702 echo $PATCH ":" $DESC
705 printers=`lpstat -a | grep "accepting" | sort | uniq | wc -l`
709 ==================================================
710 $printers Installed printers (from lpstat)
711 ==================================================
714 lpstat -a | grep "accepting" | sort | uniq | awk '{print $1}'
716 filesets=`ls /etc/filesets | wc -l`
720 ==================================================
721 $filesets Installed filesets (from /etc/filesets)
722 ==================================================
743 printers=`lpstat -a | grep "accepting" | sort | uniq | wc -l`
746 ==================================================
747 $printers Installed printers (from lpstat)
748 ==================================================
752 lpstat -a | grep "accepting" | sort | uniq | awk '{print $1}'
754 filesets=`swlist -x one_liner="name revision title" -l product | grep -v "#" | wc -l`
759 ==================================================
760 $filesets Installed filesets (from swlist -l product )
761 ==================================================
763 swlist -x one_liner="name revision title" -l product | \
764 grep -v "#" | cut -c1-60
775 SARSTAT="<NOT Running>"
776 if [ -d /var/sadm/sa ]; then
777 logs=`find /var/sadm/sa -mtime -1 -print | wc | awk '{print $1}'`
778 if [ "$logs" -gt "0" ]; then
782 VXSTAT="<NOT Running>"
783 PSOUT=`$PSCMD | grep vxconfigd | grep -v grep | wc | awk '{print $1}'`
784 if [ "$PSOUT" -gt "0" ]; then
793 sar(1M) status : $SARSTAT
794 Veritas Volume Mgr : $VXSTAT
798 if [ -x /usr/sbin/vxdg ]; then
799 echo "List Disk Groups"
800 echo "================"
803 if [ -x /usr/sbin/vxprint ]; then
805 echo "Display Configuration Summary"
806 echo "============================="
809 if [ -x /usr/sbin/vxstat ]; then
811 echo "Volume Statistics"
812 echo "================="
813 vxstat 2>&1 | tail +3 | awk '
815 printf (" OPERATIONS BLOCKS AVG TIME(ms)\n");
816 printf ("TYP NAME READ WRITE READ WRITE READ WRITE\n");
827 printf ("%s %-20s %9s %9s %10s %10s %5.1f %5.1f\n", v,n,or,ow,br,bw,ar,aw)
830 if [ -x /usr/sbin/vxprint ]; then
832 echo "Configuration Details"
833 echo "====================="
837 showrev -p 2>&1 | grep -v 'No patches' | awk '{print $2}' >$TMPFILE
838 patchnum=`cat $TMPFILE | wc | awk '{print $1}'`
842 ==================================================
843 $patchnum Installed patches (from 'showrev -p')
844 ==================================================
847 if [ $NOPATCHES -eq 0 ]; then
851 lpstat -a | grep "accepting" | sort | uniq | awk '{print $1}' >$TMPFILE
852 lpnum=`cat $TMPFILE | wc | awk '{print $1}'`
856 ==================================================
857 $lpnum Installed printers (from lpstat)
858 ==================================================
861 if [ $NOPRINTER -eq 0 ]; then
866 pkginfo | sort -b +1 >$TMPFILE
867 pkgnum=`cat $TMPFILE | wc | awk '{print $1}'`
871 ==================================================
872 $pkgnum Installed packages (from pkginfo)
873 ==================================================
876 if [ $NOPKGS -eq 0 ]; then
889 ==================================================
890 Installed printers (from lpc stat)
891 ==================================================
894 lpc stat | grep : | cut -d':' -f1
899 # =============================================================================
900 # END OF FUNCTION DEFINITIONS
901 # =============================================================================
904 # system-independant functions
908 if [ "$AUDIT" = "0" ]; then
909 exec > /usr/tmp/`hostname`.SysConfig
921 # system-dependant functions
924 HPUX09) HPUX09_Func;;
925 HPUX10) HPUX10_Func;;
926 Solaris) SOLARIS_Func;;