#!/bin/ksh
#!/bin/ksh -xv
#
# $Id: pncheck,v 1.1 2023/03/27 21:23:12 root Exp root $
#
# The following code is Confidential and is covered by the installation license
# (c) Copyright Fortra, LLC. and its group of companies.
#
#&& Check the status of nmon and the ability to compile
#
#& Can be used to confirm nmon is okay and the status of compiling possibility
#&
#& If nmon appears to not be working:
#&       . /etc/pn.conf
#&       ${nminst}/pncheck
#& ### Details will be in file /tmp/helpsystems_tmp/pncheck.mpginc ### 
#
echo "Running `grep "\$\I\d\:" ${0} | awk '{print $3,$4,$5,$6}' ` "
#
# Load nminst variable from /etc/pn.conf
.  /etc/pn.conf
cd ${nminst}
echo "Installed at ${nminst}"
echo q | $nminst/nmon > /dev/null
jstat=$?

echo "# ################ #" | tee /tmp/helpsystems_tmp/pncheck.mpginc
if [ ${jstat} -eq 0 ] ; then
  echo "nmon appears to be okay" | tee -a /tmp/helpsystems_tmp/pncheck.mpginc
else
  echo "nmon appears to be erroring" | tee -a /tmp/helpsystems_tmp/pncheck.mpginc
fi
echo "# ################ #" | tee /tmp/helpsystems_tmp/nmstatus.mpginc
ls -al nmon | tee -a /tmp/helpsystems_tmp/nmstatus.mpginc
jfile=`ls -al nmon | awk '{print $NF}'`
echo "$jfile `strings $jfile | grep ^nmon\ [0-9] | uniq `" | awk '{if (NF == 3)print "Version", $1,$3} {if (NF == 2)print "Version", $1,$2}' | tee -a /tmp/helpsystems_tmp/nmstatus.mpginc
file $jfile | tee -a /tmp/helpsystems_tmp/nmstatus.mpginc
echo "# ################ #" | tee -a /tmp/helpsystems_tmp/pncheck.mpginc
ps -ef | grep nmon | grep -v grep | tee -a /tmp/helpsystems_tmp/pncheck.mpginc
echo "# ################ #" | tee -a /tmp/helpsystems_tmp/pncheck.mpginc
if [ -s /etc/issue ] ; then
echo "#=== /etc/issue  ===#" | tee -a /tmp/helpsystems_tmp/pncheck.mpginc
   cat /etc/issue | tee -a /tmp/helpsystems_tmp/pncheck.mpginc
else
   echo "/etc/issue does not exist" | tee -a /tmp/helpsystems_tmp/pncheck.mpginc
fi
ls -al /etc/*elease* 2>/dev/null > /tmp/helpsystems_tmp/pncheck_release.mpginc
if [ -s /tmp/helpsystems_tmp/pncheck_release.mpginc ] ; then
   echo "#=== /etc/*release* without equals  ===#" | tee -a /tmp/helpsystems_tmp/pncheck.mpginc
   cat /etc/*elease* | grep -v '=' | sort | uniq | tee -a /tmp/helpsystems_tmp/pncheck.mpginc
else
   echo "Files /etc/*release* do not exist" | tee -a /tmp/helpsystems_tmp/pncheck.mpginc
fi
echo "# ################ #" | tee -a /tmp/helpsystems_tmp/pncheck.mpginc

echo "uname -a (`uname -a`)" | tee -a /tmp/helpsystems_tmp/pncheck.mpginc
echo "#===          ===#" | tee -a /tmp/helpsystems_tmp/pncheck.mpginc
echo "uname -s (`uname -s`), uname -m (`uname -m`), uname -n (`uname -n`), uname
 -p (`uname -p`)" | tee -a /tmp/helpsystems_tmp/pncheck.mpginc

echo "#=== compiling required files ===#" | tee -a /tmp/helpsystems_tmp/pncheck.mpginc
for jcmp in ssh make gcc
do
   which $jcmp 2>/dev/null
   if [ $? -eq 0 ]; then
      echo "$jcmp OK" | tee -a /tmp/helpsystems_tmp/pncheck.mpginc
   else
      echo "*** $jcmp Missing ***" | tee -a /tmp/helpsystems_tmp/pncheck.mpginc
   fi
done


jsys=`uname -s`
if [ "x${jsys}x" != "xLinuxx" ]; then
   echo "#### You cannot compile Linux nmon on ${jsys} ####" | tee -a /tmp/helpsystems_tmp/pncheck.mpginc
   echo "#### There are executables already available from IBM  ####" | tee -a /tmp/helpsystems_tmp/pncheck.mpginc
   echo "`which nmon`" | tee -a /tmp/helpsystems_tmp/pncheck.mpginc
   echo "`which topas_nmon`" | tee -a /tmp/helpsystems_tmp/pncheck.mpginc
else
   echo "#=== How 2 get gcc, ncurses, ssh, make, or other files ===#" | tee -a /tmp/helpsystems_tmp/pncheck.mpginc
   for jcmp in "yast zypper yum apt-get apt-cache "
   do
      which $jcmp 2>/dev/null | tee -a /tmp/helpsystems_tmp/pncheck.mpginc
   done
   fi

. /etc/pn.conf
mpg="cd ${nminst}"
alias lt='ls -altr'
set -o vi

echo "### Details are in /tmp/helpsystems_tmp/pncheck.mpginc ### "

#& ========================== 
#& # Sample run AIX 
#& ========================== 
#& Running pncheck,v 1.3 2018/01/12 19:25:02
#& Installed at /usr/local/mpg
#& # ################ #
#& nmon appears to be okay
#& # ################ #
#& lrwxrwxrwx    1 root     system            9 Aug 31 08:36 nmon -> /bin/nmon
#& /bin/nmon: shell script
#& # ################ #
#&     root 10158232        1   0 00:01:03      -  0:02 /usr/bin/topas_nmon  -m /usr/local/mpg -F /usr/local/mpg/mpg_20180112.nmon -s300 -c287 -t -I 0.02 -youtput_dir=/usr/local/mpg/mpg_20180112.nmon -ystart_time=00:01:02,Jan12,2018
#& # ################ #
#& /etc/issue does not exist
#& Files /etc/*release* do not exist
#& # ################ #
#& uname -a (AIX AIX720 1 7 00F62C2C4C00)
#& #===          ===#
#& uname -s (AIX), uname -m (00F62C2C4C00), uname -n (AIX720), uname -p (powerpc)
#& #=== compiling required files ===#
#& /usr/bin/ssh
#& ssh OK
#& /usr/bin/make
#& make OK
#& *** gcc Missing ***
#& #### You cannot compile Linux nmon on AIX ####
#& #### There are executables already available from IBM  ####
#& /usr/bin/nmon
#& /usr/bin/topas_nmon
#& ### Details are in /tmp/helpsystems_tmp/pncheck.mpginc ###
#&
#& ========================== 
#& # Sample run Linux 
#& ========================== 
#& Running pncheck,v 1.3 2018/01/12 19:25:02
#& Installed at /usr/local/mpg
#& # ################ #
#& nmon appears to be okay
#& # ################ #
#& lrwxrwxrwx. 1 root root 19 Aug 14 11:18 nmon -> nmon_power_64_linux
#& Version nmon_power_64_linux 16f
#& nmon_power_64_linux: ELF 64-bit MSB executable, 64-bit PowerPC or cisco 7500, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=acfe7cd0539495ee144e06b8030f3b237464bec7, not stripped
#& # ################ #
#& root     18315     1  0 00:01 ?        00:00:02 /usr/local/mpg/nmon -m /usr/local/mpg -F /usr/local/mpg/mpg_20180112.nmon -s300 -c287 -t -I 0.02
#& # ################ #
#& #=== /etc/issue  ===#
#& \S
#& Kernel \r on an \m
#&
#& #=== /etc/*release* without equals  ===#
#&
#& cpe:/o:redhat:enterprise_linux:7.3:ga:server
#& Red Hat Enterprise Linux Server release 7.3 (Maipo)
#& # ################ #
#& uname -a (Linux mpgrh7 3.10.0-514.21.2.el7.ppc64 #1 SMP Sun May 28 17:12:03 EDT 2017 ppc64 ppc64 ppc64 GNU/Linux)
#& #===          ===#
#& uname -s (Linux), uname -m (ppc64), uname -n (mpgrh7), uname -p (ppc64)
#& #=== compiling required files ===#
#& /bin/ssh
#& ssh OK
#& /bin/make
#& make OK
#& /bin/gcc
#& gcc OK
#& #=== How 2 get gcc, ncurses, ssh, make, or other files ===#
#& /bin/yum
#& ### Details are in /tmp/helpsystems_tmp/pncheck.mpginc ###
