#!/bin/ksh

ETR=/tmp/wm/wm.etr
COMMS=/tmp/wm/wm.comms
OUTFILE=/h/bmetzger/s/tmp/bppload.csv

. /opt/platform7/lbin/profile
. /etc/opt/platform7/share/env/p7profile
export PATH=$PATH:/opt/p7ctf/bin/


if [ -f ${OUTFILE} ]; then rm ${OUTFILE}; fi


# create current copy of files required

count=`ls /var/opt/platform7/tmp/*.tlf 2>/dev/null | wc -l `
# count=2;   # uncomment if you don't want to dump ETR

 if ((${count} > 0))
   then
         print "ETR is locked.  Will continue using existing files. "
    else
         print  "ETR is available.  Dumping ETR "
         time p7config -db ${ETR}    2> /dev/null

         print  "Dumping comms config "
          p7updatecomms -d ${COMMS}   > /dev/null 2>&1
    fi


#for f in m001ilm1p3
#for f in `/opt/platform7/lbin/list_processors -b ` 
for f in `/opt/platform7/lbin/list_processors -b | grep m007` 
do
    if ping $f -n2 2>&1 >/dev/null
    then
#       date | awk '{printf("%-12s ", "'$f'") }'

       ip=`awk '$2 == "'$f'" {printf("%s", $1) }' /etc/hosts`
       bpp_line=`grep ^14BPP ${COMMS} | grep -E "$ip" | sed -e 's/:/./g'`

      #BPP       :13 .site.cc.slot:number 
      #14BPP2C1S1:13 .1   .1 .2   :172.17.250.122
      #14BPP7C5S1:13 .1   .5 .7   :172.17.250.57

      site_numb=`echo $bpp_line | cut -d "." -f 3`
      cardcage=`echo $bpp_line | cut -d "." -f 4`
      slot=`echo $bpp_line | cut -d "." -f 5`
      # prep the BPPs
       remsh $f level 1 > /dev/null
       remsh $f forward 1 > /dev/null

       #FORCE COMPUTERS CPCI-736 = BPP version 1
       #ADVANTECH MIC-3390 = BPP version 2

       bppmodel=`remsh $f showHardwareModel | cut -d ":" -f 2 |sed -e 's/ /_/g'`
       cpu_peak=`p7syshealthstat -site $site_numb -cc $cardcage -bpp  $slot -cpu -peak -raw | grep CPU | awk '{FS=","; {printf ("%3.2f", $6)} }'`
#       p7syshealthstat -site $site_numb -cc $cardcage -bpp  $slot -cpu -peak -raw | grep CPU 
#       p7syshealthstat -site $site_numb -cc $cardcage -bpp  $slot -cpu -peak -raw | grep CPU | awk '{FS=","; {printf ("%.2f", $6)} }'

       date | awk '{printf ("%s,%s,%s,%s,%s,%s,%s\n", "'$f'", "'$ip'", "'$site_numb'", "'$cardcage'", "'$slot'", "'$cpu_peak'", "'$bppmodel'" )}' >> ${OUTFILE}

#ONLINE CS # p7syshealthstat -site 1 -cc 1 -bpp  5  -raw -mem -cpu -peak
#----------------------
#01,01,05,TIME,2008-06-23 17:02:03
#01,01,05,SITE,m001,172.17.250.132
#01,01,05,BPP,m001ilm1p5,172.17.250.125
#01,01,05,CPU,PEAK,0,2008-06-23 17:02:03
#01,01,05,MEM,PEAK,88.15,2008-06-23 13:02:03
#01,01,05,BUFF,PEAK,99.99,2008-06-23 17:01:33

    else
       date | awk '{printf ("%s,%s,%s,%s,%s not_pingable\n", "'$f'", "'$ip'", "'$site_numb'", "'$cardcage'", "'$slot'" )}'  >> ${OUTFILE}
        print
    fi

done

rcp ${OUTFILE} m7sstra1:/tmp/wm
echo "${OUTFILE} copied to tra1"

mailx -s "BPP load bppload.csv copied to tra1"  bill_metzger@agilent.com  </h/bmetzger/s/cron.check.bpp.load




