#!/bin/sh
# $Id: support.sh,v 1.10.4.1 2003/12/19 18:44:51 $
#***************************************************************************
#* $VRTScprght: Copyright 1993 - 2004 VERITAS Software Corporation, All Rights Reserved $
#***************************************************************************
#?
#$ Script used to gather information to aid in problem solving.
#$ It is recommended to run this script by piping it through tee.
#$
#$   support -i | tee -a /tmp/support.out
#$
#? Usage:
#?   support [-h|i]
#?
#?     -i      Ask for additional information.
#?
#?     -h      List this help information.


# Issue help

full_help() {

grep '^#[?\$]' $0 | cut -c3-
exit 2
}

cmd_help() {

grep '^#\?' $0 | cut -c3-
exit 2
}

# Confirm an action with a no for default
#
#       confirm_no prompt_string
#
#       Returns 0 for yes and 1 for no.

confirm_no ()
{
  sleep 1
  nb_echo "\n$1 (y/n) [n] \c" 1>&2
  read ans
  case $ans in
     Y*|y*) return 0 ;;
       *) return 1 ;;
  esac
}

LSDEV ()
{
  nb_echo "
===================== LSDEV ====================="
  lsdev $1
}

# nb_echo - interpret '\t' and '\c' with echo

nb_echo () {

	# The builtin echo command for most of our UNIX servers is
	# sufficient.  For Linux we need to add the "-e" argument.

	echo_name=`uname`
	case "$echo_name" in
	Linux*)	echo_command="echo -e" ;;
	*)	echo_command="echo" ;;
	esac
	$echo_command "$@"
}


############################################
########### MAIN ###########################
############################################

PATH=/usr/5bin:/usr/bin:/bin:/usr/sbin:/etc:/usr/etc:$PATH
PATH=/usr/openv/netbackup/bin:/usr/openv/netbackup/bin/admincmd:$PATH
PATH=/usr/openv/volmgr/bin:$PATH

ISROOT=`id | egrep "^uid=0\("`
if [ "${ISROOT}" = "" ] ; then
  nb_echo "
`basename $0` must be run while logged in as root. ABORTING.
"
  exit 1
fi
OS_TYPE=`uname -s`
OS_TYPE=${OS_TYPE}`uname -r`
INTERACTIVE=0

if [ $# -eq 1 ] ; then
	if [ "${1}" = "-h" ] ; then
		full_help
	elif [ "${1}" = "-i" ] ; then
		INTERACTIVE=1
	else
		cmd_help
	fi
elif [ $# -ne 0 ] ; then
	cmd_help
fi

nb_echo OS_TYPE ${OS_TYPE}
nb_echo "support \$Revision: 1.10.4.1 $ Listing - VERITAS"
nb_echo "
UNAME: `uname -a`"
nb_echo "
DATE: `date`
"
if [ -f /etc/motd ] ; then
  cat /etc/motd
fi

nb_echo " 
==================== VERSION ===================="
if [ -f /usr/openv/netbackup/version ] ; then
  nb_echo
  cat /usr/openv/netbackup/version
  HARDWARE=`head -1 /usr/openv/netbackup/version | cut -f2 -d" "`
fi
if [ -f /usr/openv/pack/pack.summary ] ; then
  nb_echo
  cat /usr/openv/pack/pack.summary
fi
if [ -f /usr/openv/netbackup/bin/version ] ; then
  nb_echo 
  cat /usr/openv/netbackup/bin/version
fi
if [ -f /usr/openv/volmgr/version ] ; then
  nb_echo
  cat /usr/openv/volmgr/version
fi
if [ -f /usr/openv/hsm/version ] ; then
  nb_echo
  cat /usr/openv/hsm/version
fi

nb_echo "
==================== ACCESS CONTROL INFO ==============="
if [ ! -f /usr/openv/netbackup/bin/goodies/support/support_nbac ] ; then
	nb_echo "support_nbac not found."
elif [ "${INTERACTIVE}" -eq 1 ] ; then
	/usr/openv/netbackup/bin/goodies/support/support_nbac -i 2>&1
else
	/usr/openv/netbackup/bin/goodies/support/support_nbac 2>&1
fi

nb_echo "
==================== LICENSE INFO ==============="
if [ ! -f /usr/openv/netbackup/bin/admincmd/get_license_key ] ; then
        nb_echo "get_license_key not found."
else
        if [ -f /usr/openv/var/license.txt ] ; then
                /usr/openv/netbackup/bin/admincmd/get_license_key -L keys
                /usr/openv/netbackup/bin/admincmd/get_license_key -L features
        else
                nb_echo "No license key file found"
        fi
fi

if [ -d /usr/openv/netbackup/client ] ; then
	nb_echo "
================ CLIENT VERSIONS ================"
	cd /usr/openv/netbackup/client
	find . -name version -print | xargs grep NetBackup | sed s/':'/'     	'/
fi

nb_echo "
==================== BP.CONF ===================="
cat /usr/openv/netbackup/bp.conf

if [ -f /usr/openv/volmgr/vm.conf ] ; then
	nb_echo "
==================== VM.CONF ===================="
cat /usr/openv/volmgr/vm.conf
else
	nb_echo "
================== NO VM.CONF ==================="
fi

nb_echo "
================ BPCLNTCMD -SELF ================"
bpclntcmd -self
nb_echo "
NIS master	`ypwhich`"

nb_echo "
================= NETSTAT -IAN =================="
netstat -ian 
nb_echo "
IFCONFIG:"
OLDIF=
for i in `netstat -in | awk '{print $1 }'` ; do
   if [ $i != "Name" ] ; then
      if [ $i != "lo0" ]; then
         if [ $i != "$OLDIF" ]; then
            ifconfig $i 2> /dev/null
            OLDIF="$i"
         fi
      fi
   fi
done

nb_echo "
====================== DF ======================="
case $OS_TYPE in
  AIX*)
	/bin/df
	LSDEV "-C"
	;;
  IRIX*)
	/bin/df -i
        nb_echo "
=================== FSD.AUTO ===================="
	cat /etc/fsd.auto
	nb_echo "
=================== HINV LIST ==================="
	/sbin/hinv
	;;
  HP*)
	/usr/bin/bdf -i
	nb_echo "
================== IOSCAN LIST =================="
        ioscan -f
	;;
  Linux*)
	/bin/df
        nb_echo "
================== PROC/CPUINFO ================="
        cat /proc/cpuinfo
        nb_echo "
==================== PROC/SCSI =================="
        cat /proc/scsi/scsi
        nb_echo "
==================== FDISK -l ==================="
        /sbin/fdisk -l
        ;;
  OSF1*)
	/bin/df -i
	LSDEV
	nb_echo "
=================== HWMGR ==================="
	/sbin/hwmgr -v d
	;;
  SunOS5*)
	/bin/df -k
	nb_echo "
================== MEMORY SIZE =================="
	/etc/prtconf | grep Memory
	nb_echo "
================== ST.CONF =================="
	cat /kernel/drv/st.conf | grep -v "^#" | sed -e '/^$/d'
	;;
  *)
	nb_echo unsupported system type.
	;;
esac

nb_echo "
================= BPCONFIG -U ==================="
if [ -f /usr/openv/netbackup/bin/admincmd/bpconfig ] ; then
	/usr/openv/netbackup/bin/admincmd/bpconfig -U
else
	nb_echo "File not found."
fi

nb_echo "
================= BPGETCONFIG ==================="
if [ -f /usr/openv/netbackup/bin/admincmd/bpgetconfig ] ; then
	/usr/openv/netbackup/bin/admincmd/bpgetconfig
else
	nb_echo "File not found."
fi

nb_echo "
================= BPSTULIST -U ==================="
if [ -f /usr/openv/netbackup/bin/admincmd/bpstulist ] ; then
	/usr/openv/netbackup/bin/admincmd/bpstulist -U
else
	nb_echo "File not found."
fi

nb_echo "
================= BPSYNCINFO ==================="
if [ -f /usr/openv/netbackup/bin/admincmd/bpsyncinfo ] ; then
	/usr/openv/netbackup/bin/admincmd/bpsyncinfo
else
	nb_echo "File not found."
fi

nb_echo "
================= NDMP_DEBUG ==================="
if [ -f /usr/openv/volmgr/database/ndmp_debug ] ; then
	cat /usr/openv/volmgr/database/ndmp_debug
else
	nb_echo "File not found."
fi

nb_echo "
================= NUMBER_DATA_BUFFERS ==================="
if [ -f /usr/openv/netbackup/db/config/NUMBER_DATA_BUFFERS ] ; then
	cat /usr/openv/netbackup/db/config/NUMBER_DATA_BUFFERS
else
	nb_echo "File not found."
fi

nb_echo "
================= SIZE_DATA_BUFFERS ==================="
if [ -f /usr/openv/netbackup/db/config/SIZE_DATA_BUFFERS ] ; then
	cat /usr/openv/netbackup/db/config/SIZE_DATA_BUFFERS
else
	nb_echo "File not found."
fi

nb_echo "
================= NET_BUFFER_SZ ==================="
if [ -f /usr/openv/netbackup/NET_BUFFER_SZ ] ; then
	cat /usr/openv/netbackup/NET_BUFFER_SZ
else
	nb_echo "File not found."
fi

nb_echo "
================= BEHAVIOR ==================="
if [ -f /usr/openv/netbackup/db/config/behavior ] ; then
	cat /usr/openv/netbackup/db/config/behavior
else
	nb_echo "File not found."
fi

if [ -f /usr/openv/volmgr/bin/tpconfig ] ; then
  nb_echo "
================= TPCONFIG -D ==================="
  /usr/openv/volmgr/bin/tpconfig -d
fi

if [ -f /usr/openv/volmgr/bin/vmoprcmd ] ; then
  nb_echo "
================= VMOPRCMD -D ==================="
  /usr/openv/volmgr/bin/vmoprcmd -d
fi

nb_echo "
================= VMDAREQ -DISPLAY ==================="
if [ -f /usr/openv/volmgr/bin/vmdareq ] ; then
	/usr/openv/volmgr/bin/vmdareq -display
else
	nb_echo "File not found."
fi

if [ -f /usr/openv/volmgr/bin/vmglob ] ; then
  nb_echo "
================ VMGLOB -LISTALL ================"
  /usr/openv/volmgr/bin/vmglob -listall -java
fi

if [ -f /usr/openv/volmgr/bin/scan ] ; then
  nb_echo "
===================== SCAN ======================"
  /usr/openv/volmgr/bin/scan
fi

nb_echo "
==================== IPCS -A ===================="
ipcs -a

nb_echo "
================== ENVIRONMENT =================="
env

nb_echo "
=================== NETBACKUP ==================="
cd /usr/openv/netbackup
ls -al

nb_echo "
================= NETBACKUP/BIN ================="
cd /usr/openv/netbackup/bin
ls -al

nb_echo "
================= NETBACKUP/BIN/ADMINCMD ========"
cd /usr/openv/netbackup/bin/admincmd
ls -al

nb_echo "
============== NETBACKUP/DB/CONFIG =============="
cd /usr/openv/netbackup/db/config
ls -al

nb_echo "
===================== VOLMGR ===================="
cd /usr/openv/volmgr
ls -al

nb_echo "
=================== VOLMGR/BIN =================="
cd /usr/openv/volmgr/bin
ls -al

nb_echo "
================ VOLMGR/DATABASE ================"
cd /usr/openv/volmgr/database
ls -al

nb_echo "
================== OPENV/LIB =================="
cd /usr/openv/lib
ls -al

nb_echo "
=============== OPENV/LIB:CKSUM ============"
cd /usr/openv/lib
find /usr/openv/lib -type f -exec cksum {} \;
find . -type l -exec ls -l {} \;

nb_echo "
================== OPENV/SHARE =================="
cd /usr/openv/share
ls -al

grep \$Revision: external_*

nb_echo "
=============== LTID DUMP TABLES ================"
/usr/openv/volmgr/bin/ltid -tables -f /tmp/ltidDUMP
if [ -f /tmp/ltidDUMP ] ; then
  cat /tmp/ltidDUMP
  rm  -f /tmp/ltidDUMP
fi

nb_echo "
=============== DB/JOBS/JOB.CONF ================"
if [ -f /usr/openv/netbackup/db/jobs/job.conf ] ; then
  cat /usr/openv/netbackup/db/jobs/job.conf
else
  nb_echo "None Found."
fi

nb_echo "
================= MEDIA ERRORS =================="
if [ -f /usr/openv/netbackup/db/media/errors ] ; then
  cat  /usr/openv/netbackup/db/media/errors
else
  nb_echo "None Found."
fi

nb_echo "
================== ACTIVE MM LOGS =================="
if [ -d /usr/openv/volmgr/debug ] ; then
	cd /usr/openv/volmgr/debug
	ls -C

	ls -l */*
else
	nb_echo "/usr/openv/volmgr/debug not found."
fi

nb_echo "
================== ACTIVE NB LOGS =================="
cd /usr/openv/netbackup/logs
ls -C

ls -l */*


nb_echo "
================== VOLUME LIST =================="
vmquery -bx -a

nb_echo "
================== MEDIA LIST ==================="
bpmedialist

nb_echo "
============== ACTIVE NB/MM PROCESSES =============="
bpps -a

if [ -d /usr/openv/netbackup/client ] ; then
	nb_echo "
============== CLIENTS CONFIGURED ==============="
	bpplclients -allunique
fi

nb_echo "
================= PACK HISTORY ================="
INSTALL_DIR=/usr/openv
PATCH_HISTORY=$INSTALL_DIR/pack/pack.history
ECHO=nb_echo
AWK=awk
if [ ! -f $PATCH_HISTORY ] ; then
      ${ECHO} "No packs installed or history file deleted. "
else

  packs_installed=`grep "Install pack" ${PATCH_HISTORY} | ${AWK} '{print $3}' | sort -u `
  attempt_packs=`${ECHO} $packs_installed | wc -w | ${AWK} '{print $1}'`
  if [ $attempt_packs -gt 0 ] ; then
    ${ECHO} "You have installed ${attempt_packs} pack."
    last_pack="bad"
    for pack in $packs_installed
    do
       not_good=""
       not_good=`grep "${pack} completed" ${PATCH_HISTORY}`
       if [ "${not_good}X" = "X" ] ; then
           ${ECHO} "	${pack} NOT installed sucessfully."
       else
           ${ECHO} "	${pack} successfully installed."
       fi
       last_pack="$pack"
    done
  else
    ${ECHO} "You have no packs installed."
  fi
fi

nb_echo "
================ SYSTEM PATCHES ================="
case $OS_TYPE in
  AIX*)
	/usr/bin/lslpp -L ;;
  IRIX*)
	/usr/sbin/showprods -Mn | grep patch ;;
  HP*)
	swlist -l patch ;;
  Linux*)
        /bin/rpm -qi -changelog kernel
        /bin/rpm -V kernel ;;
  SunOS5*)
	/usr/bin/showrev -a ;;
  *)	# OSF1*
	nb_echo "	     unsupported system type."
	;;
esac

nb_echo "
================ /ETC/SYSTEM ================="
if [ -f /etc/system ] ; then
	cat /etc/system
else
	nb_echo "File not found."
fi

nb_echo "
================ /ETC/NSSWITCH.CONF ================="
if [ -f /etc/nsswitch.conf ] ; then
	cat /etc/nsswitch.conf
else
	nb_echo "File not found."
fi

nb_echo "
================ /ETC/RESOLV.CONF ================="
if [ -f /etc/resolv.conf ] ; then
	cat /etc/resolv.conf
else
	nb_echo "File not found."
fi

case ${OS_TYPE} in
	AIX*)
		syslog="/var/adm/messages /var/adm/ras/syslog" ;;
	HP*)
		syslog=/var/adm/syslog/syslog.log ;;
	IRIX*)
		syslog=/var/adm/SYSLOG ;;
	Linux*)
		syslog="/var/log/syslog /var/log/messages" ;;
	OSF1*)
		syslog=/var/adm/messages ;;
	SunOS5*)
		syslog=/var/log/syslog ;;
	*)
		syslog="unknown" ;;
esac

for log in ${syslog}
do
	nb_echo "
================ ${log} ================="

	if [ -f ${log} ] ; then
		tail -50 ${log}
	fi
done

# Support wanted sgscan moved to just before the end
# because sometimes it hangs.

nb_echo ${OS_TYPE} | grep SunOS > /dev/null 2>&1
if [ $? -eq 0 ] ; then
	if [ -d /dev/sg ] ; then
		nb_echo "
================== SGSCAN LIST =================="
		sgscan conf -v
	else
		LSDEV
	fi
fi

nb_echo "
================= BPERROR -ALL ==================="
if [ -f /usr/openv/netbackup/bin/admincmd/bperror ] ; then
	/usr/openv/netbackup/bin/admincmd/bperror -all
else
	nb_echo "File not found."
fi

nb_echo "
==================== NB-Java ===================="
if [ -d /usr/openv/java ] ; then
	nb_echo "
====== Contents of /usr/openv/java directory ===="
	ls -alR /usr/openv/java
else
	nb_echo "
======= Directory /usr/openv/java not found ====="
fi

java_files="/usr/openv/java/auth.conf \
	/usr/openv/netbackup/bin/jbpSA \
	/usr/openv/netbackup/bin/jnbSA \
	/usr/openv/java/nbj.conf \
	/usr/openv/java/.nbjConf"

for file in $java_files
do
	if [ -f $file ] ; then
		nb_echo "
============== $file ==============" 
		cat $file
	else
		nb_echo "
======= $file not found ======="
	fi	
done

nb_echo ${OS_TYPE} | grep SunOS > /dev/null 2>&1
if [ $? -eq 0 ] ; then
	nb_echo "
======= JDK ======="
	pkginfo | grep JDK
fi

# Don't care if xrdb command is not found, so keeping this simple ...
nb_echo "
======= Keyboard focus X resource info ==========="
case $OS_TYPE in
  HP*)
	xrdb -query | grep keyboardFocusPolicy ;;
  SunOS5*)
	xrdb -query | grep keyboardFocusPolicy ;;
  Linux*)
	xrdb -query | grep keyboardFocusPolicy ;;
  *)
	nb_echo "        unsupported system type." ;;
esac

if [ $INTERACTIVE = 1 ] ; then
	nb_echo "
========= JAVA WORKSTATION DISPLAY INFO ========="
	nb_echo "Are you using the NBJava Windows Display Console to remotely"
	nb_echo "administer NetBackup? \c"
	read disp
	nb_echo $disp
	nb_echo
	nb_echo "What X window manager are you using if running on a non-SGI machine? \c"
	read wmgr
	nb_echo $wmgr
	nb_echo
fi

#
# Get the /usr/openv/msg/.conf* files that map locales
#
conf_files="`ls -1 /usr/openv/msg/.conf* 2> /dev/null`"
if [ " ${conf_files}" != " " ] ; then
	nb_echo "
======== /usr/openv/msg/.conf files ========
`ls -l /usr/openv/msg/.conf*`" 
	for file in $conf_files
	do
		nb_echo "
============== $file ==============" 
		cat $file
	done
else
	nb_echo "
======== No /usr/openv/msg/.conf files exist ========"
fi

#
# Run the locale command to see how things are set.
#
nb_echo "
========== Output From locale Command ==========="
(locale) 2> /dev/null
if [ $? -ne 0 ] ; then
	nb_echo "locale command failed or not found"
fi

#
# Grep the locale lines out of the log files.
#
nb_echo "
========= Locale Lines In Java GUI LOGS ========="
if [ -d /usr/openv/java/logs ] ; then
	cd /usr/openv/java/logs
	ls -1tr *.log | xargs grep -i "locale"
else
	nb_echo "Directory /usr/openv/java/logs does not exist."
fi
