HEX
Server: Apache/2.4.34 (Red Hat) OpenSSL/1.0.2k-fips
System: Linux WORDPRESS 3.10.0-1160.118.1.el7.x86_64 #1 SMP Thu Apr 4 03:33:23 EDT 2024 x86_64
User: digital (1020)
PHP: 7.2.24
Disabled: NONE
Upload Files
File: //opt/perf/bin/netglance
#!/bin/sh
# @(#)        netglance       11.00.020       25FEB2010
###########################################################################
# $Source: /crm/gp/source/netglance/netglance $
###########################################################################
###########################################################################
#
# oops:
#
#
# description:
#   This routine logs error message
#
#
############################################################################
oops() {
  # display error message to stdout and status file, then exit
  echo "$COMMAND : `date` ****" | tee -a $STATUSFILE 2>/dev/null
  preface="ERROR: "
  while [ $# -gt 0 ]; do
    echo "${preface}$1" | tee -a $STATUSFILE 2>/dev/null
    preface="       "
    shift
  done
  exit 1
} # end oops

noglance() {
  oops "gpm (xglance) and glance are either not found in $GLANCE_BIN_DIR" \
       "on system $NODENAME or are not executable. Check if GlancePlus" \
       "is installed on that system."
}

parse_options() {
  # if there's no arguments passed in then we prompt:
  NODENAME=""
  GLANCETYPE="gpm"
  while [ $1 ]
  do
    case $1 in
      -glance)
        GLANCETYPE="glance"
        shift
        ;;
      -*)
        echo "Usage: $0 [-glance] [system]" >&2
        exit 1
        ;;
      *) # assume the nodename
        if [ "$NODENAME" = "" ]
        then
          NODENAME="$1"
          shift
        else
          oops "This script must be executed with only one system selected." \
               "  usage:  $SCRIPTNAME [-glance] [hostname]"
        fi
        ;;
    esac
  done

  if [ "$NODENAME" = "" ]
  then
    query="Enter system name to run Glance on: "
    echo  "$query"
    read NODENAME
    if [ "$NODENAME" = "" ]
    then
      echo "No system selected"
      exit
    fi
  fi
} # end parse_options



gethostinfo() {

     LOCALSYS=`uname -s`
     LOCALREV=`uname -r`

     if [ $? != 0 ]
     then
        oops "Unable to get Local System info - uname command failed."
     fi

     if [ -f /etc/.relid ]
     then
        LOCALSYS="NCR"
        LOCALREV=`cat /etc/.relid | awk ' /RELEASE/ { print $3 }'`
     fi

     case "$LOCALSYS" in
       *HP-UX)
         LOCALSYS="HP-UX"
         RSHBIN="remsh"
         if [ "`echo $LOCALREV | awk '/8\.0/'`" = "$LOCALREV" ]
         then
           STATUSDIR="/usr/perf/log/`hostname`"
           STATUSFILE="$STATUSDIR/status.$SCRIPTNAME"
         elif [ "`echo $LOCALREV | awk '/9\.0/'`" = "$LOCALREV" ]
         then
           STATUSDIR="/usr/perf/log/`hostname`"
           STATUSFILE="$STATUSDIR/status.$SCRIPTNAME"
         elif [ "`echo $LOCALREV | awk '/10\.*/'`" = "$LOCALREV" ]
         then
           STATUSDIR="/var/opt/perf/"
           STATUSFILE="$STATUSDIR/status.$SCRIPTNAME"
         elif [ "`echo $LOCALREV | awk '/11\.*/'`" = "$LOCALREV" ]
         then
           STATUSDIR="/var/opt/perf/"
           STATUSFILE="$STATUSDIR/status.$SCRIPTNAME"
           else
             oops "Software is not available for $LOCALSYS $LOCALREV."
         fi
         ;;

       *AIX*)
         LOCALSYS="AIX"
         RSHBIN="rsh"
         STATUSDIR="/var/opt/perf/"
         STATUSFILE="$STATUSDIR/status.$SCRIPTNAME"
         ;;

       *NCR*)
         LOCALSYS="NCR"
         RSHBIN="rsh"
         STATUSDIR="/var/opt/perf/"
         STATUSFILE="$STATUSDIR/status.$SCRIPTNAME"
         ;;

       *SINIX*)
         LOCALSYS="SINIX"
         RSHBIN="rsh"
         STATUSDIR="/var/opt/perf/"
         STATUSFILE="$STATUSDIR/status.$SCRIPTNAME"
         ;;

       *SunOS*)
         LOCALSYS="SUN"
         RSHBIN="rsh"
         STATUSDIR="/var/opt/perf/"
         STATUSFILE="$STATUSDIR/status.$SCRIPTNAME"
         ;;

       *Linux*)
         LOCALSYS="Linux"
         RSHBIN=rsh
         STATUSDIR="/var/opt/perf/"
         STATUSFILE="$STATUSDIR/status.$SCRIPTNAME"
         ;;
        
       *)
         oops "Unable to run the software locally on system type $LOCALSYS."
         ;;
    esac

}


getosname() {
    SYS="`$REMSHNODE 'uname -s'`"
    if [ $? != "0" ]
    then
      oops "User $GLANCEUSER has no $RSHBIN access to $NODENAME." \
           "" \
           "User $GLANCEUSER  must have user $RSHBIN access to $NODENAME before" \
           "this script is executed.  The script will utilize the current" \
           "user name unless it is overridden by exporting a different user" \
           "name in the variable name GLANCEUSER.  Before starting PerfView" \
           "type" \
           "   export GLANCEUSER=username" \
           "where username is the name of a user who has $RSHBIN (remote shell)" \
           "access to fix this problem."
    elif [ "$SYS " = " " ]
    then 
      oops "Encountered problem obtaining uname -s for $NODENAME via $RSHBIN"
    fi
    
    
    case "$SYS" in
      *HP-UX)
        SYS="HP-UX"
        REV="`$REMSHNODE 'uname -r'`"
        XTERM="/usr/bin/X11/hpterm"
        ;;

      *Sun*)
        SYS="SUN"
        REV="`$REMSHNODE 'uname -r'`"
        XTERM="/usr/openwin/bin/xterm"
        ;;

      *AIX*)
        SYS="AIX"
        REV=`$REMSHNODE 'uname -v'`.`$REMSHNODE 'uname -r'`
        XTERM="/usr/bin/X11/xterm"
        ;;

      *SINIX*)
        SYS="SINIX"
        REV=`$REMSHNODE 'uname -v'`.`$REMSHNODE 'uname -r'`
        XTERM="/usr/bin/X11/xterm"
        ;;

      *Linux*)
        SYS="Linux"
        REV="`$REMSHNODE 'uname -r'`"
        if [ "$GLANCETYPE" = "gpm" ]; then
           GLANCETYPE=xglance
        fi
        XTERM="/usr/bin/X11/xterm"
        ;;

      *)
        REV=`$REMSHNODE "cat /etc/.relid" | awk ' /RELEASE/ { print $3 }'`
        if [ "$REV" != "" ]
        then
          SYS="NCR"
          XTERM="/usr/bin/X11/xterm"
        else
          oops "Software is not available for $SYS systems."
        fi
        ;;
    esac

}
# 
# 
############################################################################
#
# getglancedir:
#
# Global Variable Set:
#
#   GLANCE_BIN_DIR
#   VUF
#
# Description:
#   This routine sets up the GLANCE_BIN_DIR depending on the system's
#   type and OS version number
#
#############################################################################
getglancedir() {

#First get the OS Name and the Version number
getosname

# getosname() returns a valid os name and version

case "$SYS" in
    *HP-UX)
      #check for supported systems...
      if [ "`echo $REV | awk '/8\.0/'`" = "$REV" ]
      then
        VUF="8.0"
        GLANCE_BIN_DIR="/usr/perf/bin"
      elif [ "`echo $REV | awk '/9\.0/'`" = "$REV" ]
      then
        VUF="9.0"
        GLANCE_BIN_DIR="/usr/perf/bin"
      elif [ "`echo $REV | awk '/10\.*/'`" = "$REV" ]
      then
        VUF="10.*"
        GLANCE_BIN_DIR="/opt/perf/bin"
      elif [ "`echo $REV | awk '/11\.*/'`" = "$REV" ]
      then
        VUF="11.*"
        GLANCE_BIN_DIR="/opt/perf/bin"
      else
        oops "Software is not available for revision $REV of $SYS."
      fi
      ;;

    SUN)
      #check for supported systems...
      if [ "`echo $REV | awk '/4\.1/'`" = "$REV" ]
      then
        VUF="4.1"
        GLANCE_BIN_DIR="/usr/perf/bin"
      elif [ "`echo $REV | awk '/5\./'`" = "$REV" ]
      then
        VUF="5.*"
        GLANCE_BIN_DIR="/opt/perf/bin"
      else
        oops "Software is not available for revision $REV of $SYS."
      fi
      ;;

    AIX)
     # check for supported systems.....
     if [ "`echo $REV | awk '/3\.2/'`" = "$REV" ]
     then
       VUF="3.2"
       GLANCE_BIN_DIR="/usr/lpp/perf/bin"
     elif [ "`echo $REV | awk '/4\.*/'`" = "$REV" ]
     then
       VUF="4.*"
       GLANCE_BIN_DIR="/usr/lpp/perf/bin"
     else
       oops "Software is not available for revision $REV of $SYS."
     fi
     ;;

    SINIX)
     #check for supported systems...
     if [ "`echo $REV | awk '/5\.4/'`" = "$REV" ]
     then
       VUF="5.4*"
       GLANCE_BIN_DIR="/opt/perf/bin"
     else
       oops "Software is not available for revision $REV of $SYS."
     fi
     ;;

    NCR)
     # Support All NCR OS
     VUF=$REV
     GLANCE_BIN_DIR="/opt/perf/bin"
     ;;

    Linux)
     VUF=$REV
     GLANCE_BIN_DIR="/opt/perf/bin"
     ;;

    *)
     oops "Software is not available for revision $REV of $SYS."
     ;;
esac

}   #end of getglancedir() 
    
        

start_local() {

if [ "$SYS" = "HP-UX" ];
then
  HPTERM="/usr/bin/X11/hpterm"
elif [ "$SYS" = "SUN" ];
then
    HPTERM="/usr/openwin/bin/xterm"
else
  HPTERM="/usr/bin/X11/xterm"
fi

# If a ~/glance/.glancerc exists assume, assume ~/glance is HOME for glance.
[ -f $HOME/glance/.glancerc ] && HOME=$HOME/glance

if [ "$GLANCETYPE" = "gpm" -o "GLANCETYPE" = "xglance" ]
then
    if [ -x $GLANCE_BIN_DIR/$GLANCETYPE ]
    then
      GLANCECMD="$GLANCE_BIN_DIR/$GLANCETYPE"
    else
      if [ -x $GLANCE_BIN_DIR/glance ]
      then
        GLANCE_TYPE="glance"
        GLANCECMD ="$GLANCE_BIN_DIR/glance"
      else
        GLANCECMD=""
      fi 
   fi

   # Check for Glance command

   if [ "$GLANCECMD" = "" ]
   then
      noglance
   fi
   # Everything is OK --  Start glance 
   if [ "$GLANCETYPE" = "gpm" -o "$GLANCETYPE" = "xglance" ]
   then
     $GLANCECMD 1> /dev/null 2>&1 &
   else   # start glance (character mode)
     $HPTERM -display $DISPLAY -T Glance@NODENAME -n Glance -e $GLANCECMD
   fi

# GLANCETYPE not gpm/xglance (request for character mode glance)
else
    if [ -x $GLANCE_BIN_DIR/glance ]
    then
      GLANCECMD="$GLANCE_BIN_DIR/glance"
    else
      GLANCECMD=""
    fi


    if [ "$GLANCECMD" = "" ]
    then
      noglance
    fi
    # Everything is OK --  Start glance 
    $HPTERM -display $DISPLAY -T Glance@NODENAME -n Glance -e $GLANCECMD

fi # GLANCETYPE not gpm/xglance

}  #end of start_local()



start_remote() {
 
# remote execution:
# If we are at this level, then we do have user access to the System
# we are planning to run $RSHBIN on. This is tested in getosname()
 
 
 case "$SYS" in
     *HP-UX* | *SUN* | *AIX* | *NCR* | *SINIX* | *Linux* )
         #do nothing. These are supported systems
         ;;
     *)
         oops "Glance Software is not available for $SYS."
         ;;
     esac
 
 
 
 
 if [ "$GLANCETYPE" = "gpm" -o "$GLANCETYPE" = "xglance" ]
 then
     GPMEXE="$GLANCE_BIN_DIR/$GLANCETYPE"
     GLANCEXE="$GLANCE_BIN_DIR/glance"
     FOUND=`$REMSHNODE "ls $GPMEXE | wc -l" 2>/dev/null`
     if [ "$FOUND" = "" ] || [ $FOUND != 1 ]
     then
       FOUND=`$REMSHNODE "ls $GLANCEXE | wc -l" 2>/dev/null`
       if [ "$FOUND" = "" ] || [ $FOUND != 1 ]
       then
         noglance
       fi
       # glance found
       GLANCETYPE="glance"
       GLANCECMD="$GLANCEXE"
     else # gpm found
       GLANCECMD="$GPMEXE"
     fi
 else   # the user selected to run glance not gpm/xglance
 
     GPMEXE="$GLANCE_BIN_DIR/gpm"
     GLANCEXE="$GLANCE_BIN_DIR/glance"
     FOUND=`$REMSHNODE "ls $GLANCEXE | wc -l" 2>/dev/null`
 
     if [ "$FOUND" = "" ] || [ $FOUND != 1 ]
     then
       noglance
     fi
     # glance is found
     GLANCETYPE="glance"
     GLANCECMD="$GLANCEXE"
fi


   CURTERM="$TERM"   # current TERM for the system from which this executing

   SHELL="`$REMSHNODE uname -r`"
   if [ "$SHELL" = "/bin/csh" ]
   then
     SETCMD="setenv OPENWINHOME /usr/openwin; \
             setenv LD_LIBRARY_PATH /usr/openwin/lib; \
             setenv TERM $CURTERM"
   else
     # If a ~/glance/.glancerc exists assume, assume ~/glance is HOME for
     # glance (sh only).
     SETCMD="TERM=$CURTERM; [ -f $HOME/glance/.glancerc ] && HOME=$HOME/glance"
   fi


   if [ "$SYS" = "NCR" ]
   then
     $REMSHNODE "$SETCMD;nohup $XTERM -display \
                 $DISPLAY -fn "*-normal-*-17-*-m-*-iso8859-*"\
                 -T Glance@$NODENAME -n Glance -e $GLANCECMD" &
   else
     $REMSHNODE "$SETCMD;nohup $XTERM -display \
                 $DISPLAY -T Glance@$NODENAME -n Glance -e $GLANCECMD" &
 fi

}    # end of start_remote

    
        


###
#
#
#  MAIN BODY
#
#
###


  PATH=$PATH:/bin:/usr/bin:/usr/ucb:/usr/ccs/bin:/sbin:/usr/bin/X11
  export PATH

  # Set up message prefix - "PV" if this script is named "pvglance", "NG" if
  # this script is named "netglance" (in PerfView and Glance packages,
  # respectively.
  SCRIPTNAME="`basename $0`"
  COMMAND="**** $SCRIPTNAME"

  # parse the options
  gethostinfo
  parse_options $@

  if [ "`echo $NODENAME | sed -e '1s/\..*/ /'`" = `uname -n` ]
  then
    REMSHNODE="ksh -c"
    NODE_LOCATION="local"
  else
    # Check to see if user exported GLANCEUSER name to be used in $RSHBIN,
    # otherwise let $RSHBIN default to current user
    if [ "$GLANCEUSER" = "" ]
    then
      GLANCEUSER=`whoami`
    fi
    REMSHNODE="$RSHBIN $NODENAME -l $GLANCEUSER -n"
    NODE_LOCATION="remote"
  fi

  # figure out the directory where glance exist
  getglancedir

#  # check to see if running on local or remote system:
#  if [ `echo $NODENAME | sed -e '1s/\..*/ /'` = `uname -n` ]
  if [ "$NODE_LOCATION" = "local" ]
  then
    start_local
  else
    start_remote
  fi

  exit 0


#############################################################################
#
#
#   THE END     THE END     THE   END
#
#############################################################################