#!/bin/ksh 

# added ping tests
#       total_diskspace
#       ifpc firmware rev
# 25 march - test for tape drives

WORKDIR=/tmp/wm
RESULTS_FILE=`hostname`.proc
CSTM_results=`hostname`.cstm
GF35_COPY=wm.gf35


function clean_up
{
  > $RESULTS_FILE
  if [ ! -d $WORKDIR ]; then mkdir $WORKDIR ; fi;
  if [ -f $WORKDIR/*.ifpc ]; then rm $WORKDIR/*.ifpc ; fi
  if [ -f $WORKDIR/*.bpp ]; then rm $WORKDIR/*.bpp ; fi
  if [ -f $WORKDIR/*.cstm ]; then rm $WORKDIR/*.cstm ; fi
  if [ -f $WORKDIR/junk* ]; then rm $WORKDIR/junk* ; fi
}

function get_unix_info
{
   ## universal info ##

   os_rev=`/usr/bin/uname -r  | awk 'FS="." {print $2}'`  # 10 or 11

   echo "hostname: `uname -n`" >> $RESULTS_FILE
   echo "model: `model`"       >> $RESULTS_FILE
   echo "os_type: `uname `"   >> $RESULTS_FILE    #hp-ux
   echo "os_rev: `uname -r`"   >> $RESULTS_FILE
   echo "software_id: `uname -i`" >> $RESULTS_FILE
   echo "timezone: `head -1 /etc/TIMEZONE | awk 'FS="=" {print $2}'`" >> $RESULTS_FILE
   echo "gateway_ip: `netstat -rn |grep default | awk '{print $2}'` " >> $RESULTS_FILE

} # end of get_unix_info

function lancard_config
{
   # Get config info for all LAN cards
   #
   lancard_count=`/usr/sbin/lanscan -ai | wc -l`
   echo "lancard_count: $lancard_count"  >>$RESULTS_FILE

   /usr/sbin/lanscan -ai | sort -k 2,2 | sed s/0x// > junk   #sort on lan field
   while read mac interface junk;
   do
       IP_address="NA"
       netmask="NA"

       IP_address=`/usr/sbin/ifconfig $interface |grep inet | sed "s/  */ /g" |cut -d " " -f 2`
       if [[ -z $IP_address ]]; then
           IP_address="NA"
       fi

       hexmask=`/usr/sbin/ifconfig $interface |grep inet | sed "s/  */ /g" |cut -d " " -f 4`
       if [[ -z $hexmask ]]
       then
           netmask="NA"
       else
             # little dance to convert hexnetmask into dotted quad

            typeset -L4 tmp1
            typeset -R4 tmp2
            # netmask has 8 characters  ffffff00  12345678
            # #begins removing at left  ${hexmask#??????}=00
            # %begins removing at right ${hexmask%??????}=ff

            cap_hexmask=`echo $hexmask |tr [a-z] [A-Z]` #bc need caps
            hexquad1=${cap_hexmask%??????} # ff
            hexquad4=${cap_hexmask#??????} # 00

            tmp1=$cap_hexmask     # 1234
            hexquad2=${tmp1#??}   # 34

            tmp2=$cap_hexmask     # 5678
            hexquad3=${tmp2%??}      # 56

            dec_quad1=`echo "ibase=16; $hexquad1" |bc`
            dec_quad2=`echo "ibase=16; $hexquad2" |bc`
            dec_quad3=`echo "ibase=16; $hexquad3" |bc`
            dec_quad4=`echo "ibase=16; $hexquad4" |bc`
            netmask="$dec_quad1.$dec_quad2.$dec_quad3.$dec_quad4"

        fi
     echo "LAN $interface $IP_address $mac $netmask"  >>$RESULTS_FILE

   done < junk
} # end lancard_config
  
function disk_config
{
#   rm /dev/rdsk/*      # get rid of old files
#   /usr/sbin/insf -e   # create new ones for devices currently attached

total_diskspace=0;    # initialize (never could get the typset -F (float) to work

export COLUMNS=160  # need to increase to get ioscan results on 2 lines 

   # had to build something for CD-ROM drives on E boxes
   /usr/sbin/ioscan -funC disk |grep -v "=" |grep -v Class | tr -s " " " " > junk  # tr removes multiple spaces
   cat junk | awk '{if ( $1 == "disk" ) {printf ("%s  %s", $7, $8)} else {printf (" %s\n", $1)} }' | 
    sed 's/\/dev\/dsk\///' > junk1

    echo "disk_count: `grep CLAIMED junk | wc -l`"  >>$RESULTS_FILE

    # cat junk1
    #  TOSHIBA  CD-ROM    /dev/rdsk/c0t2d0
    #  SEAGATE  ST34371N  /dev/rdsk/c0t5d0
    #  SEAGATE  ST34371N  /dev/rdsk/c0t6d0

    while read vendor product device
    do

          #     vendor: HP 18.2G
          # product id: MAN3184MC
          #       type: direct access
          #       size: 17783240 Kbytes

          /usr/sbin/diskinfo /dev/rdsk/$device  > $WORKDIR/junk
          if [ -s $WORKDIR/junk ];  # test if file is not empty
          then 
               # not zero length
               vendor=`grep vendor junk | awk '{print $2}'`
               product=`grep product junk | awk '{print $3}'`
               size=`grep size junk | awk '{printf("%.1f",$2/1000000)}'`
               echo $size >> junk2
               echo "DISK $device $size $product $vendor"  >>$RESULTS_FILE
          else
               size=0  
               echo "DISK $device $size $product $vendor"  >>$RESULTS_FILE
          fi
       
          #couldn't get float math to work.  Need to sum up sizes in junk2
          total_diskspace=`cat junk2 | awk '{total = total + $1}; END {print total};'`

   done  < $WORKDIR/junk1

   echo "total_diskspace: $total_diskspace" >>$RESULTS_FILE

} #end disk_config

function tapedrive_check
{
  # see if box has tape drive installed

    /usr/sbin/ioscan -f |grep tape > $WORKDIR/junk1
    tape_flag=`wc -l $WORKDIR/junk1 | awk '{print $1}'`

   if (( $tape_flag == 0 ))
       then
           tape_drive="no"
       else
           tape_drive=`cat $WORKDIR/junk1 | awk '{print $NF}'`
   fi

   echo "tape_drive: $tape_drive" >>$RESULTS_FILE

} # end of check for tape drive

function manual_info
{
  # output file is passed when calling
  # /node_info exists or created by check_for script

OUTFILE=$1

   for var in Floor Bay Street City State Zip Contact Number SN
   do
      grep $var /node_info >> $OUTFILE
   done
} # end manual_info

function access7_info
{
  if [ -f /var/opt/platform7/conf/gf36_MCIDStorage ]
  then 
         # Site:9:0:1
         # Workstation:0:0:4
         # Server:0:0:1
         # Workstation:0:0:1
         # ProbeProcessor:50:0:2
         # Datastore:29:0:26

       a7processor_type=`cat /var/opt/platform7/conf/gf36_MCIDStorage |cut -d ":" -f 1`;
  fi

  case $a7processor_type in 
               Server)
                        a7processor_number=`cat /var/opt/platform7/conf/gf36_MCIDStorage |cut -d ":" -f 4`;
                        a7processor_name="$a7processor_type$a7processor_number"  ;;

                 Site) 
                        a7processor_number=`cat /var/opt/platform7/conf/gf36_MCIDStorage |cut -d ":" -f 2`;
                        a7processor_name="$a7processor_type$a7processor_number"  ;;

          Workstation) 
                        a7processor_number=`cat /var/opt/platform7/conf/gf36_MCIDStorage |cut -d ":" -f 4`;
                        a7processor_name="ws$a7processor_number" ;;


       ProbeProcessor) 
                        site_number=`cat /var/opt/platform7/conf/gf36_MCIDStorage |cut -d ":" -f 2`;
                        slot_number=`cat /var/opt/platform7/conf/gf36_MCIDStorage |cut -d ":" -f 4`;
                        a7processor_name="s$site_number$a7processor_type$slot_number"  ;;

            Datastore) 
                        site_number=`cat /var/opt/platform7/conf/gf36_MCIDStorage |cut -d ":" -f 2`;
                        a7processor_number=`cat /var/opt/platform7/conf/gf36_MCIDStorage |cut -d ":" -f 4`;
                        a7processor_name="s$site_number$a7processor_type$a7processor_number"  ;;

                    *) a7processor_type="not access7" 
                       a7processor_name="check_gf36_MCIDStorage" ;;
  esac

  echo "a7processor_type: $a7processor_type" >> $RESULTS_FILE
  echo "a7processor_name: $a7processor_name" >> $RESULTS_FILE
} # end of access7_info


function extended_unix_info
{

       hpux=/stand/vmunix  #standard location

       GetKernelSymbol()
       {
       echo "$1/D" | \
       adb -k $hpux /dev/kmem | \
       tr "\012" " " | \
       read junk junk2 kval
       }

       rev=$(uname -r | cut -d. -f2)

       if ((rev > 10)); then
            echo "supported_bits: `getconf HW_CPU_SUPP_BITS`" >> $RESULTS_FILE
            echo "current_bits:  `getconf KERNEL_BITS`" >> $RESULTS_FILE
       else
            # kernel parm not available on 10.20
            echo "supported_bits: 32" >> $RESULTS_FILE
            echo "current_bits:  32" >> $RESULTS_FILE   # 10.20 is 32 bits
       fi

       GetKernelSymbol "processor_count"
       echo "number_processors: $kval" >> $RESULTS_FILE

       GetKernelSymbol "itick_per_tick"   #value returned is HZ
       let speed=kval/10000               # HZ/10000 = MHz
       echo "processor_speed: $speed" >> $RESULTS_FILE

        GetKernelSymbol "memory_installed_in_machine"
        let mb=kval*4/1024 # convert pages to MB
        echo "memory: $mb" >> $RESULTS_FILE

} #end extended_unix_info

function bpp_info
{

typeset -u mac_address  #so all characters will be in caps

  for bpp in `/usr/sbin/showmount`
  do
      if [[ $bpp = +([a-z][0-9]*) ]]; then  # starts with letter, followed by digit

           BPP_RESULTS_FILE=$bpp.bpp     # stand out from *.proc extension

           # ping  s001c01p0 -n 2
                #2 packets transmitted, 2 packets received, 0% packet loss
                #2 packets transmitted, 0 packets received, 100% packet loss

           # test to see if BPP is alive
            loss_value=`/etc/ping $bpp -n 1 | grep loss | awk '{print $7}' | sed s/\%//`

           if ((loss_value < 100))   # bpp is alive
           then

               # reinitialize values so they don't get reused
               model="NA";
               os_type="NA";
               os_rev="NA";
               cpu_speed="NA";
               memory="NA";
               timezone="NA";
               gateway_ip="NA";
               serial_numb="NA";
               ip_address="NA";
               subnet_mask="NA";
               mac_address="NA";

               #System Management BIOS:
               #BIOS Vendor: Phoenix Technologies LTD
               #BIOS Version: 1.2.6-AG007
               #Board Name: CPCI-730
               #Board Version: 1.0
               #Serial Number: 210755400366
               #CPU Type: Pentium II
               #Manufacturer: Intel
               #CPU Version: MMC2
               #CPU Clock: 333MHz
               #Physical Memory: 256MB

              #cpu_speed
              cpu_speed=`/opt/bacqSysMgr/local/bin/ssh $bpp -l bacqsys "/bin/cat /proc/smbios"|grep Clock | awk '{print $3}' | sed s/MHz//g`;
         
              memory=`/opt/bacqSysMgr/local/bin/ssh $bpp -l bacqsys "/bin/cat /proc/smbios"|grep Memory | awk '{print $3}' | sed s/MB//g`;
   
                #BPP Type:          FORCE
                #BPP Assembly:      J1445A
                #BPP Serial No:     210755300479
                #BPP Date:          01/01/1988

              model=`/opt/bacqSysMgr/local/bin/ssh $bpp -l bacqsys "/bin/cat /proc/BPPinfo"|grep Assembly | awk '{print $3}'`;

              timezone=`/opt/bacqSysMgr/local/bin/ssh $bpp -l bacqsys "uname -v "| awk '{print $6}'`;

              serial_num=`/opt/bacqSysMgr/local/bin/ssh $bpp -l bacqsys "/bin/cat /proc/BPPinfo"|grep Serial | awk '{print $4}'`;

              os_type=`/opt/bacqSysMgr/local/bin/ssh $bpp -l bacqsys "/bin/cat /proc/sys/kernel/ostype" |awk '{print $1 }'`;
              os_rev=`/opt/bacqSysMgr/local/bin/ssh $bpp -l bacqsys "/bin/cat /proc/sys/kernel/osrelease" |awk '{print $1 }'`;
      
                 # SERVER='172.19.131.10'
                 # IPADDR='172.19.131.201'
                 # NETMASK='255.255.255.0'
                 # GATEWAYS='172.19.131.1'
                 # HOSTNAME='s004b01p3'

                gateway_ip=`/opt/bacqSysMgr/local/bin/ssh $bpp -l bacqsys "/bin/cat /etc/network.conf"|grep -i gateways_1 |awk 'BEGIN {FS="="} {print $2}'| sed s/\'//g`;

                ip_address=`/opt/bacqSysMgr/local/bin/ssh $bpp -l bacqsys "/bin/cat /etc/network.conf"|grep -i IPADDR |awk 'BEGIN {FS="="} {print $2}'| sed s/\'//g`;

                subnet_mask=`/opt/bacqSysMgr/local/bin/ssh $bpp -l bacqsys "/bin/cat /etc/network.conf"|grep -i NETMASK |awk 'BEGIN {FS="="} {print $2}'| sed s/\'//g`;

                  #mac address
                  #s001b01p3 (59.40.5.151) at 0:80:42:12:93:30 ether
                 
                mac_address=`/usr/sbin/arp $bpp |awk '{print $4}' | sed s/://g`

                echo  "hostname: $bpp"        >> $BPP_RESULTS_FILE
                echo  "model: $model"         >> $BPP_RESULTS_FILE
                echo  "os_type: $os_type"     >> $BPP_RESULTS_FILE
                echo  "os_rev: $os_rev"       >> $BPP_RESULTS_FILE
                echo  "processor_speed: $cpu_speed" >> $BPP_RESULTS_FILE
                echo  "memory: $memory"       >> $BPP_RESULTS_FILE
                echo  "timezone: $timezone"   >> $BPP_RESULTS_FILE
                echo  "gateway_ip: $gateway_ip" >> $BPP_RESULTS_FILE
                echo  "LAN lan0 $ip_address $mac_address $subnet_mask" >> $BPP_RESULTS_FILE
                echo  "a7processor_type: BPP" >> $BPP_RESULTS_FILE
                echo  "a7processor_name: $bpp" >> $BPP_RESULTS_FILE

                if [ -f /node_info ]
                then 
                      for var in Floor Bay Street City State Zip Contact Number 
                      do
                            grep $var /node_info >> $BPP_RESULTS_FILE
                      done

                else
                      for var in Floor Bay Street City State Zip Contact Number 
                      do
                           echo "$var: NA" >> $BPP_RESULTS_FILE
                      done
                fi

                echo  "SN: $serial_num"       >> $BPP_RESULTS_FILE

           else        # 100% packet loss to bpp


                echo  "hostname: $bpp"        >> $BPP_RESULTS_FILE
                echo  "a7processor_name: unreachable" >> $BPP_RESULTS_FILE

           fi  # end of loss value < 100
      fi # end of x followed by a digig
  done
} #end of bpp_info

function ifpc_info
{

typeset -u mac_address  #so all characters will be in caps

     for hostname in `cat /home/ifpc/.rhosts` 
     do

         # ping  s001c01p0 -n 2
         #2 packets transmitted, 2 packets received, 0% packet loss
         #2 packets transmitted, 0 packets received, 100% packet loss

         # test to see if IFPC is alive
         loss_value=`/etc/ping $hostname -n 1 | grep loss | awk '{print $7}' | sed s/\%//`

         if ((loss_value < 100))   # ifpc is alive
         then     

              IFPC_RESULTS=$WORKDIR/$hostname.ifpc  #each IFPC has it' own output file

              # reinitialize values so they don't get reused
              model="NA";
              memory="NA";
              processor_speed="NA";
              os_type="NA";
              os_rev="NA";
              rom_rev="NA";
              subnet_mask="NA";
              mac_address="NA";
              ip_address="NA";
              gateway="NA";
              lancard="NA";
  
                  # remsh 172.19.156.14 revision
                  #CPU           : E7568A Rev D
                  #Slot number   : 3
                  #Memory Size   : 0x8000000
                  #VxWorks       : 5.3.1
                  #Creation date : May 13 2002, 15:32:35
                  #BSP version   : A0217
                  #ROM version   : A0210_T2

               model=`remsh $hostname revision |grep CP |sed "s/HP //g" | sed "s/  //g"| awk '{print $3}'`
               case $model in
                     E7568) IFPC_type="S-IFPC";;
                     E7568A) IFPC_type="S-IFPC";;
                         *) IFPC_type="IFPC";;
               esac
                
              #memory
                     #  Memory Size   : 0x2000000

                      tmp=`remsh $hostname revision |grep Memory |sed "s/  */ /g"| cut -d" " -f 4`
                      junk=`printf %d $tmp`  # convert hex to dec 
                      let memory=$junk/1000000

              #os_type
                      os_type=`remsh $hostname revision |grep Vx | awk '{print $1}'`

              #VxWorks Rev
             os_rev=`remsh $hostname revision |grep Vx |sed "s/  */ /g"| cut -d" " -f 3`

              #ROM Rev (for c.08)
             rom_rev=`remsh $hostname revision |grep ROM |sed "s/  */ /g"| cut -d" " -f 4`


            # remsh s001c01p0 ifShow
            # lan (unit number 0):
            #      Internet address: 141.184.222.21
            #      Broadcast address: 141.184.222.255
            #      Netmask 0xffff0000 Subnetmask 0xffffff00
            # lo (unit number 0):
            #      Internet address: 127.0.0.1
            #      Netmask 0xff000000 Subnetmask 0xff000000

              #netmask
                      hexmask=`remsh $hostname ifShow |grep Subnet |sed "s/0x//g" |sed "s/  */ /g" |head -1 |cut -d" " -f 5`
                  # little dance to convert hexnetmask into dotted quad
                 typeset -L4 tmp1
                 typeset -R4 tmp2
                 # netmask has 8 characters  ffffff00  12345678
                 # #begins removing at left  ${hexmask#??????}=00
                 # %begins removing at right ${hexmask%??????}=ff

                 cap_hexmask=`echo $hexmask |tr [a-z] [A-Z]` #bc need caps
                 hexquad1=${cap_hexmask%??????} # ff
                 hexquad4=${cap_hexmask#??????} # 00

                 tmp1=$cap_hexmask     # 1234
                 hexquad2=${tmp1#??}   # 34

                 tmp2=$cap_hexmask     # 5678
                 hexquad3=${tmp2%??}   # 56

                 dec_quad1=`echo "ibase=16; $hexquad1" |bc`
                 dec_quad2=`echo "ibase=16; $hexquad2" |bc`
                 dec_quad3=`echo "ibase=16; $hexquad3" |bc`
                 dec_quad4=`echo "ibase=16; $hexquad4" |bc`

                 netmask="$dec_quad1.$dec_quad2.$dec_quad3.$dec_quad4"

              #mac address
                        # Ethernet address is 08:00:09:fb:f0:5b
                 
                      mac_address=`remsh $hostname ifShow |grep Ethernet |sed "s/://g" |sed "s/  */ /g"| cut -d" " -f 5`

              #ip_address
                      ip_address=`remsh $hostname ifShow |grep Internet |grep -v 127.0.0 |sed "s/  */ /g" |head -1 |cut -d" " -f 4`
               #lancard
               #gateway
                         # ROUTE NET TABLE
                         # destination      gateway          flags  Refcnt  Use           Interface
                         # ------------------------------------------------------------------------
                         # 0.0.0.0          141.184.222.11   3      0       0             lan0
                         # 141.184.222.0    141.184.222.21   1      6       6590173       lan0


               remsh $hostname routeShow |grep -E "lan|dc" |grep -v 0.0.0 | tail -n 1 | sed "s/  */ /g" > junk
               gateway_ip=`grep -E "lan|dc" junk | awk '{print $2}'`
               lancard=`grep -E "lan|dc" junk |awk '{print $6}'`
     

                echo "hostname: $hostname" >> $IFPC_RESULTS
                echo "model: $model"       >> $IFPC_RESULTS
                echo "os_type: $os_type"   >> $IFPC_RESULTS
                echo "os_rev: $os_rev"     >> $IFPC_RESULTS
                echo "rom_rev: $rom_rev"   >> $IFPC_RESULTS
                echo "memory: $memory" >> $IFPC_RESULTS
                echo "gateway_ip: $gateway_ip" >> $IFPC_RESULTS
                echo "LAN $lancard $ip_address $mac_address $netmask" >> $IFPC_RESULTS
                echo "a7processor_type: $IFPC_type" >> $IFPC_RESULTS
  
             fi  

          done #processing hostname passed

} #end ifpc_info


function diag_results
{
  # used to get memory, PDC rev, and serial number(if avail), if online diags is installed

  if [ -f /usr/sbin/cstm ];  # file exists, diags installed
  then
       diags_installed=yes

       echo "map;wait;selall;wait;info;wait;infolog;view;done" | /usr/sbin/cstm > $CSTM_results

       # Load order for cooling purposes(per HP, 1, 3, 4, 2)

       #  C360 (ws21) 
       #    Memory Board Inventory 
       #     
       #                      Total Phys  Configured  Disabled   
       #        Board         Size (MB)   Total (MB)  Total (MB) 
       #        ------------  ----------  ----------  ----------
       #          EXT0 0a/0b         256         256           0  
       #          EXT0 1a/1b         256         256           0  
       #                      ----------  ----------  ---------- 
       #       System Total:         512         512           0  
       #
       #  Bank Inventory 
       # 
       #                                                                      Inter
       #    Log.  Phys                Size                                    leave
       #    Bank  Bank  Board         (MB)  Disabled?  SPA Range (Hex)        Group
       #    ----  ----  ------------  ----  ---------  ---------------------  -----
       #       3     0    EXT0 0a/0b   128  enabled    0x00000000 - 1fffffff     0
       #       7     1    EXT0 0a/0b   128  enabled    0x00000000 - 1fffffff     0
       #      10     0    EXT0 1a/1b   128  enabled    0x00000000 - 1fffffff     0
       #       8     1    EXT0 1a/1b   128  enabled    0x00000000 - 1fffffff     0


       # D330 (m013)
       #     Memory Board Inventory 
       # 
       #                  Total Phys  Configured  Disabled   
       #    Board         Size (MB)   Total (MB)  Total (MB) 
       #    ------------  ----------  ----------  ----------
       #           0A/0B         128         128           0  
       #           1A/1B         128         128           0  
       #                  ----------  ----------  ---------- 
       #   System Total:         256         256           0  


       #  D370 (m7altsrv)
       #     Memory Board Inventory 
       # 
       #                  Total Phys  Configured  Disabled   
       #    Board         Size (MB)   Total (MB)  Total (MB) 
       #    ------------  ----------  ----------  ----------
       #      EXT0 0a/0b         256         256           0  
       #      EXT0 1a/1b         128         128           0  
       #      EXT0 2a/2b         128         128           0  
       #                  ----------  ----------  ---------- 
       #   System Total:         512         512           0  
       # 
       # Bank Inventory 
       #  
       #                                                                       Inter
       #     Log.  Phys                Size                                    leave
       #     Bank  Bank  Board         (MB)  Disabled?  SPA Range (Hex)        Group
       #     ----  ----  ------------  ----  ---------  ---------------------  -----
       #        9     0    EXT0 0a/0b   128  enabled    0x10000000 - 1fffffff     1
       #       10     1    EXT0 0a/0b   128  enabled    0x10000000 - 1fffffff     1
       #        3     0    EXT0 1a/1b    64  enabled    0x00000000 - 0fffffff     0
       #        4     1    EXT0 1a/1b    64  enabled    0x00000000 - 0fffffff     0
       #        1     0    EXT0 2a/2b    64  enabled    0x00000000 - 0fffffff     0
       #        6     1    EXT0 2a/2b    64  enabled    0x00000000 - 0fffffff     0

       # Marlmaw1 model=9000/785/B2000  total slots=4
       #
       #     Memory Board Inventory
       #     DIMM Slot      Size (MB)
       #     ---------      ---------
       #          00            256
       #     ---------      ---------
       #     System Total (MB):   256


       # VzW model=9000/800/L2000-44 rp5400 total slots=8
       # 16 slots total.  4a/b-7a/b disabled on rp5400 but enabled on rp5450 (user guide)
       # Memory Board Inventory
       # 
       #    DIMM Slot      Size (MB)
       #    ---------      ---------
       #           0a            512
       #           2a            512

        # Determine model for case 
        # 9000/813/D330      -> D330
        # 9000/800/A400-6X   -> A400
        # 9000/800/HPServerBlade8600/3xx2  -> 
                                              # cleans up -6X    | cleans up 3xx2
        mach=`model |sed -e 's/[0-9]*\///g' | sed -e 's/\-.*//g' | sed -e 's/3xx2//g'`
#        mach=`model | awk 'BEGIN {FS="/"} ; { print $3};`


        case $mach in
               D200|D210|D220|D230|D310|D320|D330)

                 sed -e '/^    Bank/,/^$/!d' $CSTM_results > junk2 ;
                 slots_used=`grep [0-9][aA] junk2 |wc -l`;
                 total_slots=8 ;
                 ((slots_avail = $total_slots - $slots_used))

                 echo "diags_installed: $diags_installed"  >> $RESULTS_FILE
                 echo "total_slots: $total_slots"          >> $RESULTS_FILE
                 echo "slots_used: $slots_used"            >> $RESULTS_FILE
                 echo "slots_available: $slots_avail"      >> $RESULTS_FILE

                 # get rid of / seperating boards
                 cat junk2 | sed -e 's/\// /g' | sed -e 's/EXT0 / /g'|
                 awk '{if ($1 ~ /[0-9]/) {print $2" " $3 " "$4" "$5}}' |
                 awk '{if ($1 == 0) {printf ("RAM %s %s\n", $2, $NF)}
                       else {printf ("RAM %s %s\n", $3, $NF)}
                      }' >> $RESULTS_FILE

                 grep "PDC Firmware Revision:" $CSTM_results | 
                 awk '{printf ("PDC_rev: %s\n", $4)}' >> $RESULTS_FILE;;

               D250|D350|D260|D270|D280|D360|D370|D380|D390)

                 sed -e '/^    Bank/,/^$/!d' $CSTM_results > junk2 ;  
                 slots_used=`grep [0-9][aA] junk2 |wc -l`
                 total_slots=12 ;
                 ((slots_avail = $total_slots - $slots_used))

                 echo "diags_installed: $diags_installed"  >> $RESULTS_FILE
                 echo "total_slots: $total_slots"          >> $RESULTS_FILE
                 echo "slots_used: $slots_used"            >> $RESULTS_FILE
                 echo "slots_available: $slots_avail"      >> $RESULTS_FILE

                 # get rid of / seperating boards
                 cat junk2 | sed -e 's/\// /g' | sed -e 's/EXT0 / /g'|
                 awk '{if ($1 ~ /[0-9]/) {print $2" " $3 " "$4" "$5}}' |
                 awk '{if ($1 == 0) {printf ("RAM %s %s\n", $2, $NF)}
                       else {printf ("RAM %s %s\n", $3, $NF)}
                      }' >> $RESULTS_FILE

                 grep "PDC Firmware Revision:" $CSTM_results | 
                 awk '{printf ("PDC_rev: %s\n", $4)}' >> $RESULTS_FILE;;


               A400|A500)
       
                 #  A500 (app-lab) and Bladeserver
                 #    Memory Board Inventory 
                 #
                 #   DIMM Slot      Size (MB)
                 #   ---------      ---------
                 #          01            128
                 #          02            128
                 #   ---------      ---------
                 #   System Total (MB):   256
       
                 sed -e '/^   DIMM Slot/,/^   System Total/!d' $CSTM_results > junk2
                 slots_used=`grep -E '^ *[0-9]' junk2 |wc -l`;
                 total_slots=8 ;
                 ((slots_avail = $total_slots - $slots_used))

                 echo "diags_installed: $diags_installed"  >> $RESULTS_FILE
                 echo "total_slots: $total_slots"          >> $RESULTS_FILE
                 echo "slots_used: $slots_used"            >> $RESULTS_FILE
                 echo "slots_available: $slots_avail"      >> $RESULTS_FILE

                 cat junk2 |
                 awk '{if ($1 ~ /^[0-9]/) {printf ("RAM %s %s\n", $1, $NF)}}' >> $RESULTS_FILE
 
                 # PDC rev appears more than once.  Only want one printed
                 grep PDC $CSTM_results | read var1 var2 var3 PDC_rev var5 var6
                 echo "PDC_rev: $PDC_rev" >> $RESULTS_FILE
                 unset var1 var2 var3 var5 var6;;

               L2000)
                 sed -e '/^   DIMM Slot/,/^   System Total/!d' $CSTM_results > junk2
                 slots_used=`grep -E '^ *[0-9]' junk2 |wc -l`;
                 total_slots=16 ;
                 ((slots_avail = $total_slots - $slots_used))

                 echo "diags_installed: $diags_installed"  >> $RESULTS_FILE
                 echo "total_slots: $total_slots"          >> $RESULTS_FILE
                 echo "slots_used: $slots_used"            >> $RESULTS_FILE
                 echo "slots_available: $slots_avail"      >> $RESULTS_FILE

                 cat junk2 |
                 awk '{if ($1 ~ /^[0-9]/) {printf ("RAM %s %s\n", $1, $NF)}}' >> $RESULTS_FILE
 
                 # PDC rev appears more than once.  Only want one printed
                 grep PDC $CSTM_results | read var1 var2 var3 PDC_rev var5 var6
                 echo "PDC_rev: $PDC_rev" >> $RESULTS_FILE
                 unset var1 var2 var3 var5 var6;;

               L3000)
                 # cingular 9000/800/L3000-7x
                 # Slot Num  Configured and Slot label for each DIMM (MB)
                 #    --------  --------------------------------------------
                 #                0a   2a   1a   3a   3b   1b   2b   0b
                 #              ---- ---- ---- ---- ---- ---- ---- ----
                 # 
                 #        EXT 0   512    0    0    0    0    0    0  512

                 sed -e '/^               0a/,/^       EXT/!d' $CSTM_results > junk2
                 slots_used=`grep -E '^ *[0-9]' junk2 |wc -l`;
                 sed 's/EXT 0/ /' junk2 > junk3
                 cat junk3 |awk '{if ($1 ~ /[0-9]/) {print $0}}' > junk2
                 sed 's/ \{1,5\}/ /g' junk2 > junk3  #get rid of multiple spaces

                 # junk3 now contains
                 #   0a 2a 1a 3a 3b 1b 2b 0b
                 #   512 0 0 0 0 0 0 512


                 total_slots=`grep -E '0a' junk2 |wc -w`;

                 total_slots=16 ;
                 ((slots_avail = $total_slots - $slots_used))

                 echo "diags_installed: $diags_installed"  >> $RESULTS_FILE
                 echo "total_slots: $total_slots"          >> $RESULTS_FILE
                 echo "slots_used: $slots_used"            >> $RESULTS_FILE
                 echo "slots_available: $slots_avail"      >> $RESULTS_FILE

                 cat junk2 |
                 awk '{if ($1 ~ /^[0-9]/) {printf ("RAM %s %s\n", $1, $NF)}}' >> $RESULTS_FILE
 
                 # PDC rev appears more than once.  Only want one printed
                 grep PDC $CSTM_results | read var1 var2 var3 PDC_rev var5 var6
                 echo "PDC_rev: $PDC_rev" >> $RESULTS_FILE
                 unset var1 var2 var3 var5 var6;;


               HPServerBlade|B2000|B2600)  #blade=bh3710  wst=B2000
                 sed -e '/^   DIMM Slot/,/^   System Total/!d' $CSTM_results > junk2
                 slots_used=`grep -E '^ *[0-9]' junk2 |wc -l`
                 total_slots=4;   #per HP
                 ((slots_avail = $total_slots - $slots_used))

                 echo "diags_installed: $diags_installed"  >> $RESULTS_FILE
                 echo "total_slots: $total_slots"          >> $RESULTS_FILE
                 echo "slots_used: $slots_used"            >> $RESULTS_FILE
                 echo "slots_available: $slots_avail"      >> $RESULTS_FILE

                 cat junk2 |
                 awk '{if ($1 ~ /^[0-9]/) {printf ("RAM %s %s\n", $1, $NF)}}' >> $RESULTS_FILE
 
                 # PDC rev appears more than once.  Only want one printed
                 grep PDC $CSTM_results | read var1 var2 var3 PDC_rev var5 var6
                 echo "PDC_rev: $PDC_rev" >> $RESULTS_FILE
                 unset var1 var2 var3 var5 var6;;

               "rp3410  ")    #citizens app servers (spaces matter!)
                   # Citizens app server   9000/800/rp3410 

                   #  DIMM Slot      Size (MB)
                   #   ---------      ---------
                   #          0A            512
                   #          0B            512
                   #          1A            512
                   #          1B            512
                   #   ---------      ---------
                   #   System Total (MB):  2048
 
                   # MEMORY STATUS TABLE (MB) (Current Boot Status)
                   #
                   #Slot 0a  512M    Active
                   #Slot 0b  512M    Active
                   #
                   #Slot 1a  512M    Active
                   #Slot 1b  512M    Active
                   #
                   #Slot 2a  0
                   #Slot 2b  0
                   #
                   #Slot 3a  0
                   #Slot 3b  0
                   #
                   #Slot 4a  0
                   #Slot 4b  0
                   #
                   #Slot 5a  0
                   #Slot 5b  0
                   #
                   #Subtotal 2048M

                  grep -E "Slot [0-9]" $CSTM_results > junk2
                  grep Active junk2 | sed -e 's/Slot //g' | sed -e 's/Active//g' | sed -e 's/M//g' > junk3
                  total_slots=`cat junk2 | wc -l`
                  slots_used=`cat junk2 | grep Active |wc -l`
                  slots_avail=`cat junk2 | grep -v Active |wc -l`

                 echo "diags_installed: $diags_installed"  >> $RESULTS_FILE
                 echo "total_slots: $total_slots"          >> $RESULTS_FILE
                 echo "slots_used: $slots_used"            >> $RESULTS_FILE
                 echo "slots_available: $slots_avail"      >> $RESULTS_FILE

                 cat junk3 |
                 awk '{if ($1 ~ /^[0-9]/) {printf ("RAM %s %s\n", $1, $NF)}}' >> $RESULTS_FILE
 
                 # PDC rev appears more than once.  Only want one printed
                 grep PDC $CSTM_results | read var1 var2 var3 PDC_rev var5 var6
                 echo "PDC_rev: $PDC_rev" >> $RESULTS_FILE
                 unset var1 var2 var3 var5 var6;;

            *) total_slots=1000 ;;

        esac

        # if serial number is present in diag output, replace value in /node_info
        sn_check=`grep -E "System Serial Number" $CSTM_results | wc -l`

        if ((sn_check == 1));then


            SN=`grep -E "System Serial Number" $CSTM_results | cut -d ": " -f 2`
       
# doesn't work            sed -e "s/^SN: [0-9A-Za-z]*/SN:$SN */g" /node_info

            cat /node_info | 
            awk '{ if ($1 ~ /SN:/) {print "SN:'"$SN"' *"}  #pass system variable
                    else {print}
                  }' > nodeinfo.tmp 

            cp /node_info /node_info.orig
            mv nodeinfo.tmp /node_info  # replace existing file with new one
        else
            break
        fi

#stopped here
  else    #online diags not installed

       echo "diags_installed: no"    >> $RESULTS_FILE
       echo "total_slots: NA"        >> $RESULTS_FILE
       echo "slots_used: NA"         >> $RESULTS_FILE
       echo "slots_available: NA"    >> $RESULTS_FILE
       echo "PDC_rev: NA"            >> $RESULTS_FILE

  fi
} # end of diag results
 
function check_for_node_info
{ 
  if [ -s /node_info ] # file exists and > zero length
  then 
       break  # quit this loop
  else
       cp ${WORKDIR}/node_info  /node_info  # create file from template
  fi
} #end of check_for_node_info

clean_up
check_for_node_info
get_unix_info
lancard_config
disk_config
tapedrive_check
access7_info
extended_unix_info
diag_results
manual_info  $RESULTS_FILE    # need to pass output file

if [ -f /home/ifpc/.rhosts ]; # if it's an RSP, 
then 
     bpp_info
     ifpc_info 
fi    

# cleanup
  if [ -f $WORKDIR/junk* ]; then rm $WORKDIR/junk* ; fi
#  if [ -f $WORKDIR/*.cstm ]; then rm $WORKDIR/*.cstm ; fi
  if [ -d $WORKDIR/tmp ]; then rm -r $WORKDIR/tmp ; fi
