#!/bin/sh

#    SAM-QFS_notice_begin
#
#      Solaris 2.x Sun Storage & Archiving Management File System
#
#      Copyright (c) 2006 Sun Microsystems, Inc.
#      All Rights Reserved.
#
#      Government Rights Notice
#      Use, duplication, or disclosure by the U.S. Government is
#      subject to restrictions set forth in the Sun Microsystems,
#      Inc. license agreements and as provided in DFARS 227.7202-1(a)
#      and 227.7202-3(a) (1995), DRAS 252.227-7013(c)(ii) (OCT 1988),
#      FAR 12.212(a)(1995), FAR 52.227-19, or FAR 52.227-14 (ALT III),
#      as applicable.  Sun Microsystems, Inc.
#
#    SAM-QFS_notice_end

#
#  samexplorer
#
#  samexplorer is a script that gathers information about the installed system
#  and places it in a file for SAM-FS/QFS customer support.
#
#  NOTE: this script must be run as root.
#
# $Id: samexplorer,v 1.20.2.5 2006/06/28 16:29:18 ta129963 Exp $
#

#  CONFIGURATION VARIABLES

#  Where the report goes
REPORT=${1:-/tmp/SAMreport}

#  How many lines from log files, etc., to show in the output report.
#  Default is 1,000, but your support provider may ask you to change
#  this to provide additional historical log messages.
HOW_MANY_LINES=${2:-1000}

#  The number of lines from the archiver/stager data directories to dump
DATA_DIR_LINES=2000

#  The number of lines from showqueue -v output
SHOWQUEUE_LINES=2000

#  The number of lines from each mdb invocation
MDB_LINES=100000

#  Locale for messages
LOCALE=C

#  Options for dump_cat
DUMPCATOPTS="-V"

#  END OF CONFIGURATION VARIABLES - NO CHANGES BELOW HERE, PLEASE
 
#  SAMreport name
REPORTNAME=`basename $REPORT`

#  SAMreport directory
REPORTDIR=`dirname $REPORT`

#  Directories that SAM-FS uses

ETCDIR=/etc/opt/SUNWsamfs
CUSTDIR=/etc/opt/SUNWsamfs/scripts
VARDIR=/var/opt/SUNWsamfs
CATDIR=/var/opt/SUNWsamfs/catalog
USERDIR=/opt/SUNWsamfs/bin
EXECDIR=/opt/SUNWsamfs/sbin

#  Default trace directories
TRCDIR=$VARDIR/trace
TRCTMP=/tmp/$$.trcctls

#  A tag emitted on lines indicating serious problems
TAG=":-( "

#  The prompt we fake on echoed command lines
PROMPT="`uname -n`# "

#  Function definitions

#  How many "."s on the current line?  999 means "too many".
COUNT=999

#  Note:  if you find the lines of dots aren't the same length, or you
#         get extra "."s in your output file, then check to make sure you
#         haven't done something like "verbose ls >>$REPORT", because then
#         twiddle's dot will go to the report file instead of the screen!
#         Also avoid "verbose /opt/SUNWsamfs/sbin/samcmd u 2>&1 | head -100",
#         because then twiddle's dot will go to the screen but won't get
#         counted.
twiddle()
{
    COUNT=`expr $COUNT + 1`
	if [ $COUNT -ge 45 ]; then
		COUNT=1
        echo
		/bin/echo Please wait.\\c
	fi
    /bin/echo .\\c
}

#  Warn the user that this script really should be run as root.
rerun_as_root()
{
	echo " "
	echo " "
	echo Cannot read ${1} ...  Please rerun this script as root.
	echo " "
	echo Cannot read ${1} >>$REPORT 2>&1
	echo " " >>$REPORT 2>&1
	/bin/echo Please wait.\\c
}

#  define a function to execute a command, echoing it as it does so, and
#  indent everything.

verbosei(){
    twiddle
    echo ""		>>$REPORT 2>&1
    echo "    " $PROMPT $*		>>$REPORT 2>&1
    (eval $*		| sed -e "s/^/     /" )>>$REPORT 2>&1
    echo ""		>>$REPORT 2>&1
}

#  show a file, with title and verbose echoing of the cat command, with
#  some indentation.

showifiles(){
for file in $*; do
	echo "     ------------------- $file -------------------" >>$REPORT 2>&1
	if [ -d $file -o -c $file -o -b $file -o -p $file ]; then
		verbosei /bin/ls -l $file
		echo $TAG  "     $file is a directory, char special, block special or pipe.">>$REPORT 2>&1
		echo ""		>>$REPORT 2>&1
	elif [ -r $file ]; then
		verbosei /bin/ls -l $file
		verbosei /bin/cat $file
	elif [ -f $file ]; then
		verbosei /bin/ls -l $file
		echo "    " $file is not readable >>$REPORT 2>&1
		echo ""		>>$REPORT 2>&1
    else
		echo "    " $file does not exist >>$REPORT 2>&1
		echo ""		>>$REPORT 2>&1
	fi
done
}

#  Non-indenting versions of the above functions

verbose(){
    twiddle
    echo ""		>>$REPORT 2>&1
    echo $PROMPT $*		>>$REPORT 2>&1
    eval $*		>>$REPORT 2>&1
    echo ""		>>$REPORT 2>&1
}

showfiles(){
for file in $*; do
	echo "------------------- $file -------------------" >>$REPORT 2>&1
	if [ -d $file -o -c $file -o -b $file -o -p $file ]; then
		verbose /bin/ls -l $file
		echo $TAG "$file is a directory, char special, block special or pipe.">>$REPORT 2>&1
		echo ""		>>$REPORT 2>&1
	elif [ -r $file ]; then
		verbose /bin/ls -l $file
		verbose /bin/cat $file
	elif [ -f $file ]; then
		verbose /bin/ls -l $file
		echo $file is not readable >>$REPORT 2>&1
		echo ""		>>$REPORT 2>&1
    else
		echo $file does not exist >>$REPORT 2>&1
		echo ""		>>$REPORT 2>&1
	fi
done
}

# show at least $HOW_MANY_LINES lines of a group of files

showenuf(){
ENUF=0
REM=$HOW_MANY_LINES
for file in $*; do
	echo "------------------- $file -------------------" >>$REPORT 2>&1
	if [ -d $file -o -c $file -o -b $file -o -p $file ]; then
		verbose /bin/ls -l $file
		echo $TAG "$file is a directory, char special, block special or pipe.">>$REPORT 2>&1
		echo ""		>>$REPORT 2>&1
	elif [ x`echo $file | /bin/egrep '.gz$|.Z$'` = x$file ]; then
		verbose /bin/ls -l $file
		echo $file is compressed >>$REPORT 2>&1
		echo ""		>>$REPORT 2>&1
	elif [ -r $file ]; then
		verbose /bin/ls -l $file
		ENUF=`/bin/tail -$REM $file | /bin/wc | cut -c1-8`
		verbose /bin/tail -$REM $file
		if [ $ENUF -ge $REM ]; then
			return
		else
			REM=`expr $REM - $ENUF`
		fi
	elif [ -f $file ]; then
		verbose /bin/ls -l $file
		echo $file is not readable >>$REPORT 2>&1
		echo ""		>>$REPORT 2>&1
    else
		echo $file does not exist >>$REPORT 2>&1
		echo ""		>>$REPORT 2>&1
	fi
done
}

# show just the last $HOW_MANY_LINES lines of a file

showtails(){
for file in $*; do
	echo "------------------- $file -------------------" >>$REPORT 2>&1
	if [ -d $file -o -c $file -o -b $file -o -p $file ]; then
		verbose /bin/ls -l $file
		echo $TAG "$file is a directory, char special, block special or pipe.">>$REPORT 2>&1
		echo ""		>>$REPORT 2>&1
	elif [ -r $file ]; then
		verbose /bin/ls -l $file
		verbose /bin/tail -$HOW_MANY_LINES $file
	elif [ -f $file ]; then
		verbose /bin/ls -l $file
		echo $file is not readable >>$REPORT 2>&1
		echo ""		>>$REPORT 2>&1
    else
		echo $file does not exist >>$REPORT 2>&1
		echo ""		>>$REPORT 2>&1
	fi
done
}

verbosehead(){
    twiddle
    echo ""		>>$REPORT 2>&1
    echo $PROMPT $*		>>$REPORT 2>&1
    eval $* 2>&1 | head -100		>>$REPORT 2>&1
    echo ""		>>$REPORT 2>&1
}

settrace(){
  eval ${1}TRC=`/bin/grep $2 < $TRCTMP | sed -e "s/$2 *//" | sed -e "s/^off$//"`
}

#  End of function definitions

#
#  now collect up everything...
#
echo Report is being produced into ${REPORT} ...

rm -f $REPORT
echo "SAM-FS Software Support" >$REPORT
echo " " >>$REPORT
echo "Run at `/bin/date` on `/bin/uname -n` by `/bin/id`" >>$REPORT
echo " " >>$REPORT

#  Find the log file locations in the various configuration files
if [ -f $ETCDIR/defaults.conf ]; then
	if [ -r $ETCDIR/defaults.conf ]; then
        # Strip out leading space/tab combinations
        # Strip out comment lines
        # Strip out "log = LOG_"
        # Strip out trailing space/tab/comment combinations
        # Test: "  log           = LOG_LOCAL6  # LOCAL7 already used for T3"
		LOGIS=`grep LOCAL $ETCDIR/defaults.conf | sed -e "s/^[ 	]*//g" | grep -v "^#" | sed -e "s/^.*LOG_//" | sed -e "s/[ 	].*//g"`
		if [ x$LOGIS = x ]; then
			LOGIS=local7
		fi
	else
		rerun_as_root $ETCDIR/defaults.conf
		LOGIS=local7
	fi
else
	LOGIS=local7
fi

# Get the samfs log file.
# Skip non-sam entries with patterns like "local1,...,local7.none".

if [ -f /etc/syslog.conf ]; then
	if [ -r /etc/syslog.conf ]; then
		# We decided to use the first possible entry, versus the last.
		SAMLL=`grep -i $LOGIS /etc/syslog.conf | grep -v "#" | grep -iv $LOGIS'[^;]*.none' | head -1`
		# Verify that there's a tab character in the line.
		# Watch out for invisible tab character in following line!
		SAMLM=`echo "$SAMLL" | grep "	"`
		if [ "X" = "X$SAMLM" ]; then
			echo $TAG /etc/syslog.conf entry for SAM-FS missing tab >> $REPORT 2>&1
			echo " " >> $REPORT 2>&1
			# Sometimes there will be a second entry defined properly,
			# so try the first entry with spaces versus tabs.
			# Strip out leading/trailing comma sections.
			# Test: "local7.debug  ifdef(`LOGHOST', /var/adm/sam-log, @loghost)"
			SAMLOG=`echo "$SAMLL" | sed -e "s/^.* //" -e "s/, *@.*//" -e "s/.*, *//" -e "1q"`
		else
			# Watch out for invisible tab character in following line!
			# Strip out leading/trailing comma sections.
			# Test: "local7.debug  ifdef(`LOGHOST', /var/adm/sam-log, @loghost)"
			SAMLOG=`echo "$SAMLL" | sed -e "s/^.*	//" -e "s/, *@.*//" -e "s/.*, *//" -e "1q"`
		fi
	else
		rerun_as_root /etc/syslog.conf
		SAMLOG=""
	fi
else
	SAMLOG=""
fi

#	beware - archiver.cmd et al. allow "#" anywhere to start a comment.
#   strip anything starting with "#" to the end of the line.

if [ -f $ETCDIR/archiver.cmd ]; then
	if [ -r $ETCDIR/archiver.cmd ]; then
		ARCHLOGS=`sed -e "/#/s/#.*//" < $ETCDIR/archiver.cmd|grep "logfile.*="| sed -e "/logfile/,/logfile/s/^.*= *//"`
	else
		rerun_as_root $ETCDIR/archiver.cmd
		ARCHLOGS=""
	fi
else
	ARCHLOGS=""
fi

if [ -f $ETCDIR/recycler.cmd ]; then
	if [ -r $ETCDIR/recycler.cmd ]; then
		RECLLOGS=`sed -e "/#/s/#.*//" < $ETCDIR/recycler.cmd|grep "logfile.*=" | sed -e "/logfile/,/logfile/s/^.*= *//"`
	else
		rerun_as_root $ETCDIR/recycler.cmd
		RECLLOGS=""
	fi
else
	RECLLOGS=""
fi

if [ -f $ETCDIR/releaser.cmd ]; then
	if [ -r $ETCDIR/releaser.cmd ]; then
		RELLOG=`sed -e "/#/s/#.*//" < $ETCDIR/releaser.cmd|grep "logfile.*="| sed -e "/logfile/,/logfile/s/^.*= *//"`
	else
		rerun_as_root $ETCDIR/releaser.cmd
		RELLOG=$VARDIR/releaser.log
	fi
else
	RELLOG=$VARDIR/releaser.log
fi

if [ -f $ETCDIR/stager.cmd ]; then
	if [ -r $ETCDIR/stager.cmd ]; then
		STAGER_LOG=`sed -e "/#/s/#.*//" < $ETCDIR/stager.cmd|grep "logfile.*="| sed -e "/logfile/,/logfile/s/logfile *= *//" -e "s/ .*$//"`
	else
		rerun_as_root $ETCDIR/stager.cmd
		STAGER_LOG=""
	fi
else
	STAGER_LOG=""
fi

#  These log files' locations are fixed
DEVLOGS=/var/opt/SUNWsamfs/devlog/*

#  These data directory locations are fixed
ARCHDATA="$VARDIR/archiver"
STAGER_DATA="$VARDIR/stager"

#  Find the trace files.

/opt/SUNWsamfs/sbin/samcmd d 2>/dev/null > $TRCTMP

settrace AML  sam-amld
settrace ARCH sam-archiverd
settrace CAT  sam-catserverd
settrace FSD  sam-fsd
settrace RCY  sam-recycler
settrace RFT  sam-rftd
settrace SHFS sam-sharefsd
settrace STG  sam-stagerd
settrace SVR  sam-serverd
settrace CLI  sam-clientd
settrace MGMT sam-mgmt

/bin/rm $TRCTMP

#  Make sure we're running as root.   Although most things will work,
#  without being root, we should warn the user that the report is
#  incomplete.

UID=`/bin/id | sed -e "s/^[^=]*=//" -e "s/(.*//"`
if [ $UID -ne 0 ] ; then
	echo " "
	echo "Warning:  This script should be run as 'root'."
	echo " "
    echo "    But, since you have started it as uid ${UID}, it will make the"
	echo "    best effort it can.  The output report will be missing some"
    echo "    important pieces of information, and you will probably see some"
    echo "    error messages while this script is running.  If you have access"
    echo "    to root, you should re-run this script as root."
	echo " "
	echo $TAG NOT RUN AS ROOT >> $REPORT 2>&1
	echo $TAG NOT RUN AS ROOT >> $REPORT 2>&1
	echo $TAG NOT RUN AS ROOT >> $REPORT 2>&1
	echo " " >> $REPORT 2>&1
fi

echo "This report generated into: $REPORT"   >>$REPORT
echo ""   >>$REPORT 2>&1

echo "syslogd facility code:      $LOGIS"    >>$REPORT
echo ""   >>$REPORT 2>&1

echo "SAM-FS Log:                 $SAMLOG"   >>$REPORT
echo "AMLD Trace:                 $AMLTRC"   >>$REPORT
echo "Archiver Logs:              $ARCHLOGS" >>$REPORT
echo "Archiver Traces:            $ARCHTRC"  >>$REPORT
echo "Archiver Data:              $ARCHDATA" >>$REPORT
echo "Catalog Trace:              $CATTRC"   >>$REPORT
echo "Device Logs:                $DEVLOGS"  >>$REPORT
echo "FSD Trace:                  $FSDTRC"   >>$REPORT
echo "Recycler Log:               $RECLLOGS" >>$REPORT
echo "Recycler Trace:             $RCYTRC"   >>$REPORT
echo "Releaser Log:               $RELLOG"   >>$REPORT
echo "RFTD Trace:                 $RFTTRC"   >>$REPORT
echo "Share FS Trace:             $SHFSTRC"  >>$REPORT
echo "Stager Log:                 $STAGER_LOG"   >>$REPORT
echo "Stager Trace:               $STGTRC"   >>$REPORT
echo "Stager Data:                $STAGER_DATA"  >>$REPORT
echo "Remote Server Trace:        $SVRTRC"   >>$REPORT
echo "Remote Client Trace:        $CLITRC"   >>$REPORT
echo "Mgmt Server Trace:          $MGMTTRC"  >>$REPORT
echo ""   >>$REPORT 2>&1

echo "------------------- locale --------------------------" >>$REPORT
verbose /bin/locale
LC_ALL=$LOCALE
export LC_ALL

echo "------------------- boot time -----------------------" >>$REPORT
verbose /bin/who -b

echo "------------------- uptime --------------------------" >>$REPORT
verbose /bin/uptime 

echo "------------------- system type ---------------------" >>$REPORT
SYS_TYPE=`/bin/grep -i nexus /var/adm/messages* 2>&1 | head -1 | sed -e "s/^.*nexus = //"`
if [ X = X$SYS_TYPE ]; then
    SYS_TYPE="Not Available"
fi
echo "\n$SYS_TYPE" >>$REPORT
echo "" >>$REPORT 2>&1

echo "------------------- uname ---------------------------" >>$REPORT
verbose /bin/uname -a

#
#  Check for some Solaris patches we know are required for proper operation
#  of SAM-FS.  There may be others; this list is subject to change.
#  Issue a warning if the patch isn't there; otherwise echo the full patch id.
#
SOL_VER=`uname -r | cut -c1-5`
if [ $SOL_VER = "5.9" ]; then
  NEEDED="NONE"
elif [ $SOL_VER = "5.10" ]; then
  NEEDED="NONE"
else
  NEEDED="UNKNOWN"
  echo $TAG "Unknown Solaris release level $SOL_VER"       >>$REPORT
fi

#  Start the SAM-QFS Manager diagnostic report in the background.
#  The output is saved to file /var/tmp/fsmgr.overall.log.
/opt/SUNWfsmgr/bin/fsmgr_report > /dev/null 2>&1 &

echo "------------------- application architecture info --------" >>$REPORT

verbose /bin/isainfo

echo "------------------- kernel architecture info --------" >>$REPORT

KERN_ARCH=`/bin/isainfo -kv`
KERN_VER=` echo $KERN_ARCH | cut -c1-2`
if [ X"$KERN_VER" = X64 ]; then
    echo "\nSolaris is running in 64-bit kernel mode."  >>$REPORT
else
    echo "\nSolaris is running in 32-bit kernel mode."  >>$REPORT
fi
if [ X"$KERN_ARCH" != X ]; then
    echo $KERN_ARCH                                  >>$REPORT
fi
echo "" >>$REPORT 2>&1

showfiles /etc/release
echo "" >>$REPORT 2>&1

echo "------------------- check system patches ------------" >>$REPORT
echo "\nPatches needed for Solaris ${SOL_VER}: $NEEDED\n" >>$REPORT
if [ X"$NEEDED" = "XNONE" -o X"$NEEDED" = "XUNKNOWN" ]; then
    NEEDED=""
fi

/bin/showrev -p 2>/dev/null | /bin/sed -e 's/Obso.*//' | /bin/sort > /tmp/$$.patchlist_all

for patch in $NEEDED; do
    PATCHFOUND=`/bin/grep -w $patch /tmp/$$.patchlist_all`
    if [ "X$PATCHFOUND" = "X" ]; then
      echo $TAG "Solaris patch " $patch " not installed.\n" >>$REPORT
    else
      echo "Solaris " $PATCHFOUND " installed.\n" >>$REPORT
    fi
done

echo "\nPatches installed for SAM-QFS:\n" >>$REPORT

/bin/showrev -p 2>/dev/null | egrep 'SUNWsamfs|SUNWqfs|SUNWfsmgr' | sed -e 's/Obso.*//' | sed -e 's/Patch: //' > /tmp/$$.patchlist_samqfs

echo "/bin/showrev -p | egrep 'SUNWsamfs|SUNWqfs|SUNWfsmgr' | sed -e 's/Obso.*//' | sed -e 's/Patch: //' > /tmp/$$.patchlist_samqfs\n" >>$REPORT
showifiles /tmp/$$.patchlist_samqfs
for i in `cat /tmp/$$.patchlist_samqfs`; do
    echo "/bin/ls -ld /var/sadm/patch/${i}" >>$REPORT 2>&1
    /bin/ls -ld /var/sadm/patch/${i} >>$REPORT
    echo ""   >>$REPORT 2>&1
    echo "/bin/ls -l /var/sadm/patch/${i}/log" >>$REPORT 2>&1
    /bin/ls -l /var/sadm/patch/${i}/log >>$REPORT
    echo ""   >>$REPORT 2>&1
done
rm /tmp/$$.patchlist_samqfs

echo "\nPatches installed for Solaris:\n" >>$REPORT

echo "/bin/showrev -p | /bin/sed -e 's/Obso.*//' | /bin/sort > /tmp/$$.patchlist_all\n" >>$REPORT
showifiles /tmp/$$.patchlist_all
rm /tmp/$$.patchlist_all

#
# SUNWqfsr      - Sun QFS Solaris (root)
# SUNWqfsu      - Sun QFS Solaris (usr)
# SUNWsamfsr    - Sun SAM-FS and Sun SAM-QFS Solaris (root)
# SUNWsamfsu    - Sun SAM-FS and Sun SAM-QFS Solaris (usr)
# SUNWfsmgrr    - Sun SAM-QFS File System Manager Solaris (root)
# SUNWfsmgru    - Sun SAM-QFS File System Manager Solaris (usr)
# SUNWsamtp     - Sun SAM-FS Tools Solaris (application)
# SUNWmd        - Solstice DiskSuite (system)
# SUNWmdg       - Solstice DiskSuite Tool (system)
# SUNWfcp       - Sun FCP SCSI Device Driver (system)
# SUNWfcpx      - Sun FCP SCSI Device Driver 64-bit (system)
# SUNWfctl      - Sun Fibre Channel Transport layer (system)
# SUNWfctlx     - Sun Fibre Channel Transport layer 64-bit (system)
# SUNWqlc       - Qlogic ISP 2200/2202 Fibre Channel Device Driver (system)
# SUNWqlcx      - Qlogic ISP 2200/2202 Fibre Channel Device Driver 64-bit (system)
# SUNWsmgr      - SANsurfer, QLogic Fibre Channel Administration (system)
# SANergy       - SANergy solaris (application)
# AMPXdst       - Ampex DST Tape Drive Device Driver (system)
# JNIC          - JNI Fibre Channel SCSI HBA Driver (system)
# QLA2200-3     - QLogic QLA2200 driver (system)
#
echo "------------------- package info --------------------" >>$REPORT

verbose "/bin/pkginfo | grep LSC"

for PACKAGE in SUNWqfsr SUNWqfsu SUNWsamfsr SUNWsamfsu SUNWfsmgrr SUNWfsmgru SUNWsamtp SUNWmd SUNWmdg SUNWfcp SUNWfcpx SUNWfctl SUNWfctlx SUNWqlc SUNWqlcx SUNWsmgr SANergy AMPXdst JNIC QLA2200-3
do
    twiddle
    echo "" >>$REPORT 2>&1
    verbose /bin/pkginfo -l $PACKAGE
    verbose /usr/sbin/pkgchk  $PACKAGE
done

showfiles /opt/SUNWsamfs/include/version.h

echo "------------------- kernel info ---------------------" >>$REPORT
echo ""                                      >>$REPORT 2>&1
echo "/bin/ls -l /kernel/drv/sam*"           >>$REPORT 2>&1
/bin/ls -l /kernel/drv/sam*                  >>$REPORT 2>&1
echo "/bin/ls -l /kernel/fs/sam*"            >>$REPORT 2>&1
/bin/ls -l /kernel/fs/sam*                   >>$REPORT 2>&1

echo "/bin/ls -l /kernel/drv/*/sam*"         >>$REPORT 2>&1
/bin/ls -l /kernel/drv/*/sam*                >>$REPORT 2>&1
echo "/bin/ls -l /kernel/fs/*/sam*"          >>$REPORT 2>&1
/bin/ls -l /kernel/fs/*/sam*                 >>$REPORT 2>&1
echo ""   >>$REPORT 2>&1

echo "------------------- modinfo output ------------------" >>$REPORT
verbose "/usr/sbin/modinfo | /bin/grep sam | /bin/grep -v sampling"
verbose "/usr/sbin/modinfo | /bin/grep ' sd '"
verbose "/usr/sbin/modinfo | /bin/grep ' st '"
verbose "/usr/sbin/modinfo | /bin/egrep -i 'fcp|fctl|fp|qlc|ssd|disk|tape'"

echo "------------------- driver output -------------------" >>$REPORT
echo ""   >>$REPORT 2>&1
/bin/grep Driver /var/adm/messages* 2>&1 | head -10 >>$REPORT 2>&1
echo ""   >>$REPORT 2>&1

echo "------------------- storage array info ------------------" >>$REPORT
if [ -f /usr/sbin/luxadm ]; then
	verbose /usr/sbin/luxadm qlgc
fi
#
# Disable cfgadm until bugid 4736456 is resolved.  We only
# want to run it when the proper patch is installed.
#
#if [ -f /usr/sbin/cfgadm ]; then
#	verbose /usr/sbin/cfgadm -al
#fi

echo "------------------- ls -lR /opt/SUNWsamfs ------------" >>$REPORT
verbose /bin/ls -lR  /opt/SUNWsamfs
verbose /bin/ls -lL  /opt/SUNWsamfs
for FILE in `ls -1 /opt/SUNWsamfs | grep -v "^jre$"`; do
    verbose /bin/ls -lRL /opt/SUNWsamfs/$FILE
done

echo "------------------- $ETCDIR directory ---------------" >>$REPORT
verbose /bin/ls -ld  $ETCDIR
verbose /bin/ls -lLd  $ETCDIR
verbose /bin/ls -l  $ETCDIR
verbose /bin/ls -lL $ETCDIR

echo "------------------- $VARDIR directory ---------------" >>$REPORT
verbose /bin/ls -ld  $VARDIR
verbose /bin/ls -lLd  $VARDIR
verbose /bin/ls -l  $VARDIR
verbose /bin/ls -lL $VARDIR

showfiles $ETCDIR/mcf
showfiles $ETCDIR/hosts*
showfiles $ETCDIR/defaults.conf
showfiles $ETCDIR/diskvols.conf
showfiles $ETCDIR/inquiry.conf
showfiles $ETCDIR/archiver.cmd
showfiles $ETCDIR/preview.cmd
showfiles $ETCDIR/recycler.cmd
showfiles $ETCDIR/releaser.cmd
showfiles $ETCDIR/rft.cmd
showfiles $ETCDIR/samfs.cmd
showfiles $ETCDIR/stager.cmd
showfiles $ETCDIR/mount.sh
showfiles $CUSTDIR/archiver.sh
showfiles $CUSTDIR/dev_down.sh
showfiles $CUSTDIR/load_notify.sh
showfiles $CUSTDIR/log_rotate.sh
showfiles $CUSTDIR/recover.sh
showfiles $CUSTDIR/recycler.sh
showfiles $CUSTDIR/restore.sh
showfiles $CUSTDIR/save_core.sh
showfiles $CUSTDIR/ssi.sh
showfiles $CUSTDIR/stageback.sh
showfiles $CUSTDIR/tarback.sh
showfiles /etc/syslog.conf 
showfiles /kernel/drv/samst.conf
showfiles /kernel/drv/st.conf
showfiles /kernel/drv/fp.conf
showfiles /kernel/drv/fcp.conf
showfiles /kernel/drv/jni.conf
showfiles /kernel/drv/qla*.conf
showfiles /kernel/drv/qlc.conf
showfiles /usr/kernel/drv/dst.conf 
showfiles /etc/driver_classes
showfiles /etc/driver_aliases
showfiles /etc/system

echo "------------------- /etc/system flags ---------------" >>$REPORT
if grep sam_statvfs_bias /etc/system > /dev/null; then
     echo $TAG found sam_statvfs_bias in /etc/system
fi
echo ""   >>$REPORT 2>&1

echo "------------------- samset --------------------------" >>$REPORT
echo ""   >>$REPORT 2>&1
verbose /opt/SUNWsamfs/sbin/samset
echo ""   >>$REPORT 2>&1
verbose /opt/SUNWsamfs/sbin/samset debug
echo ""   >>$REPORT 2>&1
verbose /opt/SUNWsamfs/sbin/samset devlog all

echo "------------------- hostid --------------------------" >>$REPORT
echo ""   >>$REPORT 2>&1
echo "hostid is `/usr/bin/hostid`" >>$REPORT 2>&1
echo ""   >>$REPORT 2>&1

echo "------------------- license info ---------------" >>$REPORT
verbose /opt/SUNWsamfs/sbin/samcmd l
showfiles $ETCDIR/LICENSE.*

echo "------------------- jre info ------------------------" >>$REPORT
if [ -r /opt/SUNWsamfs/jre/bin/jre -a -x /opt/SUNWsamfs/jre/bin/jre ]; then
    verbose "/opt/SUNWsamfs/jre/bin/jre -v 2>&1 | grep -i Version"
else
    echo ""   >>$REPORT 2>&1
fi

echo "------------------- network info --------------------" >>$REPORT
verbose /usr/sbin/ifconfig -a
verbose /bin/grep rpc      /etc/nsswitch.conf
verbose /bin/grep services /etc/nsswitch.conf
verbose /bin/grep sam      /etc/rpc
verbose "/bin/ypcat rpc      | grep sam"
verbose /bin/grep sam      /etc/services
verbose /bin/grep sam      /etc/yp/src/services
verbose "/bin/ypcat services | grep sam"
showfiles /etc/hostname*
showfiles /etc/inet/hosts
showfiles /etc/inet/services
showfiles /etc/nsswitch.conf

echo "------------------- ipcs info -----------------------" >>$REPORT
verbose /bin/ipcs -a

echo "------------------- /dev/samst ----------------------" >>$REPORT
verbose /bin/ls -l /dev/samst
verbose /bin/ls -Ll /dev/samst

echo "------------------- /dev/rmt ------------------------" >>$REPORT
echo ""                                      >>$REPORT 2>&1
echo "/bin/ls -l /dev/rmt/*[0-9]"            >>$REPORT 2>&1
/bin/ls -l /dev/rmt/*[0-9]                   >>$REPORT 2>&1
echo ""                                      >>$REPORT 2>&1
echo "/bin/ls -Ll /dev/rmt/*[0-9]"           >>$REPORT 2>&1
/bin/ls -Ll /dev/rmt/*[0-9]                  >>$REPORT 2>&1
echo ""                                      >>$REPORT 2>&1

echo "------------------- /dev/rdst -----------------------" >>$REPORT
echo ""                                      >>$REPORT 2>&1
echo "/bin/ls -l /dev/rdst*"                 >>$REPORT 2>&1
/bin/ls -l /dev/rdst*                        >>$REPORT 2>&1
echo ""                                      >>$REPORT 2>&1
echo "/bin/ls -Ll /dev/rdst*"                >>$REPORT 2>&1
/bin/ls -Ll /dev/rdst*                       >>$REPORT 2>&1
echo ""                                      >>$REPORT 2>&1

echo "------------------- /dev/dsk ------------------------" >>$REPORT
echo ""                                      >>$REPORT 2>&1
echo "/bin/ls -l /dev/dsk/*s2"               >>$REPORT 2>&1
/bin/ls -l /dev/dsk/*s2                      >>$REPORT 2>&1
echo ""                                      >>$REPORT 2>&1
echo "/bin/ls -Ll /dev/dsk/*s2"              >>$REPORT 2>&1
/bin/ls -Ll /dev/dsk/*s2                     >>$REPORT 2>&1
echo ""                                      >>$REPORT 2>&1

echo "------------------- /dev/rdsk -----------------------" >>$REPORT
echo ""                                      >>$REPORT 2>&1
echo "/bin/ls -l /dev/rdsk/*s2"              >>$REPORT 2>&1
/bin/ls -l /dev/rdsk/*s2                     >>$REPORT 2>&1
echo ""                                      >>$REPORT 2>&1
echo "/bin/ls -Ll /dev/rdsk/*s2"             >>$REPORT 2>&1
/bin/ls -Ll /dev/rdsk/*s2                    >>$REPORT 2>&1
echo ""                                      >>$REPORT 2>&1

echo "------------------- SANergy info --------------------" >>$REPORT
verbose '/bin/ls -l /opt/SANergy/lib /opt/SANergy/lib/sparcv9 /opt/SANergy/lib/amd64'
verbose '/bin/ls -Ll /opt/SANergy/lib /opt/SANergy/lib/sparcv9 /opt/SANergy/lib/amd64'

echo "------------------- group entry ---------------------" >>$REPORT
verbose /bin/ls -l /etc/group
verbose /bin/ls -Ll /etc/group
verbose /bin/grep SAM_FS /etc/group
verbose /bin/ypmatch SAM_FS group

showfiles /var/spool/cron/crontabs/root

showenuf /var/adm/messages\*

if [ "x$SAMLOG" = x ]; then
	echo $TAG " No sam log file defined."  >>$REPORT
else
	showenuf $SAMLOG\*
fi

for FILES in $AMLTRC $ARCHLOGS $ARCHTRC $CATTRC $DEVLOGS $FSDTRC $RECLLOGS $RCYTRC $RELLOG $RFTTRC $SHFSTRC $STAGER_LOG $STGTRC $SVRTRC $CLITRC $MGMTTRC
do
	showtails $FILES
done

showtails $VARDIR/.grau/graulog*
showtails /tmp/.grau

#
# Foreach robot or tape drive device, decode and record the last 10 tapealert
# device log entries contained in its most recent device log.
#
echo "------------------- tapealerts ----------------------" >>$REPORT
for file in $DEVLOGS; do
	if [ -r $file ]; then
		x=`/bin/basename $file`
		/bin/printf "%d" $x > /dev/null 2>&1
		if [ $? -eq 0 ]; then
			echo ""   >>$REPORT 2>&1
			echo "$file" >>$REPORT 2>&1
			/bin/tail -r $file | /bin/egrep '12006|12007' | /bin/grep TapeAlert | /bin/sed 10q | /bin/tail -r | /opt/SUNWsamfs/sbin/tapealert -i >>$REPORT 2>&1
		fi
	fi
done
echo ""   >>$REPORT 2>&1

echo "------------------- samtrace ------------------------" >>$REPORT
verbose "/opt/SUNWsamfs/sbin/samtrace -f -v | /bin/compress -c | /bin/uuencode samtrace.Z"

echo "------------------- threadlist of running system ----" >>$REPORT
if [ $UID -eq 0 ]; then
	if [ $SOL_VER = "5.9" ]; then
		echo '=n"---- date/time ----"
			time/y
			lbolt/K
			=n"---- utsname ----"
			$<utsname
			=n"---- sam_version/sam_build_uname ----"
			sam_version/s
			sam_build_uname/s
			=n"---- threadlist ----"
			$<threadlist
			=n"---- sam_ mdb end ----"' | /bin/mdb -k 2>&1 | head -$MDB_LINES >> $REPORT 2>&1
	else
		echo '=n"---- date/time ----"
			time/y
			lbolt/K
			=n"---- utsname ----"
			utsname::print
			=n"---- sam_version/sam_build_uname ----"
			sam_version/s
			sam_build_uname/s
			=n"---- threadlist ----"
			::threadlist -v
			=n"---- function call args ----"
			::walk thread | ::findstack ".$c6"
			=n"---- sam_ mdb end ----"' | /bin/mdb -k 2>&1 | head -$MDB_LINES >> $REPORT 2>&1
	fi
else
	rerun_as_root threadlist
fi

echo "------------------- stack tracebacks ----------------" >>$REPORT
if [ $UID -eq 0 ]; then
	# ps -e only returns 8 characters, so match on first 8.
	SAM_FSD=`/bin/ps -e | grep " sam-fsd$" | /bin/awk '{print $1}'`
	if [ -n "$SAM_FSD" ]; then
		echo "\n/bin/ptree $SAM_FSD"            >>$REPORT
		/bin/ptree $SAM_FSD                     >>$REPORT
		/bin/ptree $SAM_FSD > /tmp/$$.procs
		SAMPROCS=`/bin/cat /tmp/$$.procs | /bin/awk '{print $1}'`
		for PID in $SAMPROCS ; do
			verbose "/bin/pstack $PID; /bin/pflags $PID"
		done
		/bin/rm -f /tmp/$$.procs
	else
		echo "Sorry, sam-fsd process not running.\n"   >>$REPORT
	fi
else
	rerun_as_root pstack
fi

echo "------------------- mcf analysis --------------------" >>$REPORT
if [ -r $ETCDIR/mcf ]; then
    #  Check to see if two device names (/dev/rmt/0 and /dev/samst/c1t2u0, for example) 
    #  refer to the same hardware device.
	compare_devices() {
		if [ $# -ne 2 -o X$1 = X- -o X$2 = X- ]; then
			echo Only $# device name\(s\), or device name was a dash - no comparison done >>$REPORT 2>&1
        else 
			if [ ! -r $1 ]; then
				echo $TAG $1 does not exist >>$REPORT 2>&1
				return
			fi
			if [ ! -r $2 ]; then
				echo $TAG $2 does not exist >>$REPORT 2>&1
				return
			fi
			dev1=`ls -l $1 | sed -e 's,.*/devices,,' | sed -e 's,\(.*/\)[^@]*@,\1@,' -e 's,:.*,,'`
			dev2=`ls -l $2 | sed -e 's,.*/devices,,' | sed -e 's,\(.*/\)[^@]*@,\1@,' -e 's,:.*,,'`
			if [ $dev1 != $dev2 ]; then
				echo $TAG $1 and $2 do not match >>$REPORT 2>&1
				echo $TAG $1 evaluates to $dev1 >>$REPORT 2>&1
				echo $TAG $2 evaluates to $dev2 >>$REPORT 2>&1
				echo >>$REPORT 2>&1
			else
				echo $1 and $2 seem to match >>$REPORT 2>&1
			fi
		fi
	}

	lineno=0
	exec <$ETCDIR/mcf
	while read eqid eqord eqtype famset state additional
	do
		# strip comments
		case $eqid in
		\#*)
			lineno=`expr $lineno + 1`
			continue
			;;
		esac

		# strip blank lines
		case $eqtype in
		"")
			lineno=`expr $lineno + 1`
			continue
			;;
		esac

		catp1=`echo $additional | /bin/cut -c1`
		if [ X != X$catp1 ] && [ X$catp1 != "X#" ] && [ X$catp1 != "X-" ] ; then
			catpath=$additional
			if [ X$catp1 != "X/" ]; then
				catpath=$CATDIR/$additional
			fi
		else
			catpath=$CATDIR/$famset
		fi

		lineno=`expr $lineno + 1`
		echo "    " $lineno ":" $eqid $eqord $eqtype $famset $state $additional >>$REPORT

		#
		# listed in mcf(4) man page order
		#
		case $eqtype in
		'ms'|'ma')    
			;;
		'mm'|'md'|'mr'|g[0-9]*)    
			hope=`echo $eqid | sed -e "s/dsk/rdsk/"`
			if [ X != X$additional -a X- != X$additional ]; then
				if [ X$hope != X$additional ]; then
					echo $TAG raw and cooked devices do not match >>$REPORT
				else
					echo $eqid and $additional seem to match >>$REPORT
				fi
				verbosei /etc/prtvtoc $additional
			else
				verbosei /etc/prtvtoc $hope
			fi
			;;
		'rb'|'ad'|'ae'|'al'|'as'|'a1'|'q8'|'ov'|'ac'|'cy'|'ds'|'eb'|'e8'|'hc'|'hp'|'ic'|'me'|'pd'|'pg'|'ml'|'dm'|'sl'|'s9'|'sn'|'il'|'c4')
			echo "$eqtype dump_cat follows" >>$REPORT 2>&1
			echo "" >>$REPORT 2>&1
			verbose /opt/SUNWsamfs/sbin/dump_cat $DUMPCATOPTS $catpath
			echo "" >>$REPORT 2>&1
			;;
		'gr')    
			echo "GRAU/EMASS parameter file follows" >>$REPORT 2>&1
			echo "" >>$REPORT 2>&1
			showifiles $eqid
			echo "GRAU/EMASS dump_cat follows" >>$REPORT 2>&1
			echo "" >>$REPORT 2>&1
			verbose /opt/SUNWsamfs/sbin/dump_cat $DUMPCATOPTS $catpath
			echo "" >>$REPORT 2>&1
			;;
		'fj')    
			echo "Fujitsu LT300 parameter file follows" >>$REPORT 2>&1
			echo "" >>$REPORT 2>&1
			showifiles $eqid
			echo "Fujitsu LT300 dump_cat follows" >>$REPORT 2>&1
			echo "" >>$REPORT 2>&1
			verbose /opt/SUNWsamfs/sbin/dump_cat $DUMPCATOPTS $catpath
			echo "" >>$REPORT 2>&1
			;;
		'im')    
			echo "IBM parameter file follows" >>$REPORT 2>&1
			echo "" >>$REPORT 2>&1
			showifiles $eqid
			echo "" >>$REPORT 2>&1
			showifiles /etc/ibmatl.conf
			echo "IBM dump_cat follows" >>$REPORT 2>&1
			echo "" >>$REPORT 2>&1
			verbose /opt/SUNWsamfs/sbin/dump_cat $DUMPCATOPTS $catpath 
			echo "" >>$REPORT 2>&1
			;;
		'pe')    
			echo "Sony parameter file follows" >>$REPORT 2>&1
			echo "" >>$REPORT 2>&1
			showifiles $eqid
			echo "Sony dump_cat follows" >>$REPORT 2>&1
			echo "" >>$REPORT 2>&1
			verbose /opt/SUNWsamfs/sbin/dump_cat $DUMPCATOPTS $catpath 
			echo "" >>$REPORT 2>&1
			;;
		'sk')    
			echo "STK parameter file follows" >>$REPORT 2>&1
			echo "" >>$REPORT 2>&1
			showifiles $eqid
			echo "STK dump_cat follows" >>$REPORT 2>&1
			echo "" >>$REPORT 2>&1
			verbose /opt/SUNWsamfs/sbin/dump_cat $DUMPCATOPTS $catpath
			echo "" >>$REPORT 2>&1
			;;
		'hy')    
			echo "HY dump_cat follows" >>$REPORT 2>&1
			echo "" >>$REPORT 2>&1
			hist_cat=$catpath
			verbose /opt/SUNWsamfs/sbin/dump_cat $DUMPCATOPTS $catpath
			echo "" >>$REPORT 2>&1
			;;
		'od'|'o2'|'wo'|'mo'|'pu'|'mf')    
			catpath=$CATDIR/man$eqord
			if [ -f $catpath ]; then
				echo "$eqtype$eqord dump_cat follows" >>$REPORT 2>&1
				echo "" >>$REPORT 2>&1
				verbose /opt/SUNWsamfs/sbin/dump_cat $DUMPCATOPTS $catpath
				echo "" >>$REPORT 2>&1
			fi
			;;
		'tp'|'dt'|'lt'|'xt'|'xm'|'fd'|'i7'|'li'|'ib'|'m2'|'vt'|'at'|'sa'|'so'|'st'|'se'|'sg'|'d3'|'sf'|'ti')
			compare_devices $eqid $additional
			catpath=$CATDIR/man$eqord
			if [ -f $catpath ]; then
				echo "$eqtype$eqord dump_cat follows" >>$REPORT 2>&1
				echo "" >>$REPORT 2>&1
				verbose /opt/SUNWsamfs/sbin/dump_cat $DUMPCATOPTS $catpath
				echo "" >>$REPORT 2>&1
			fi
			;;
		'ss')
			echo "sam remote server parameter file follows" >>$REPORT 2>&1
			echo "" >>$REPORT 2>&1
			showifiles $eqid
			echo ""
			echo ""
			echo "Please run /opt/SUNWsamfs/sbin/samexplorer on any remote clients"
			echo "and include the SAMreports with this one. "
			COUNT=999
			;;
		'sc')
			echo "sam remote client parameter file follows" >>$REPORT 2>&1
			echo "" >>$REPORT 2>&1
			showifiles $eqid
			echo "remote client dump_cat follows" >>$REPORT 2>&1
			echo "" >>$REPORT 2>&1
			verbose /opt/SUNWsamfs/sbin/dump_cat $DUMPCATOPTS $catpath 
			echo "" >>$REPORT 2>&1
			echo ""
			echo ""
			echo "Please run /opt/SUNWsamfs/sbin/samexplorer on any remote servers"
			echo "and include the SAMreports with this one. "
			COUNT=999
			;;
		'rd')
			;;
		z?)
			echo "sam migkit library " >>$REPORT 2>&1
			echo "" >>$REPORT 2>&1
			verbosei /bin/ls -l $eqid
			verbosei /bin/ls -Ll $eqid
			;;
		*)
			echo $TAG "Unknown equipment type" >>$REPORT 2>&1
			;;
		esac
	done
elif [ -f $ETCDIR/mcf ]; then
		rerun_as_root $ETCDIR/mcf
elif [ -d $ETCDIR ]; then
		echo $TAG missing $ETCDIR/mcf >>$REPORT 2>&1
fi

if [ x$hist_cat = x ]; then
	echo "default HY dump_cat follows" >>$REPORT 2>&1
	echo "" >>$REPORT 2>&1
	verbose /opt/SUNWsamfs/sbin/dump_cat $DUMPCATOPTS $CATDIR/historian
	echo "" >>$REPORT 2>&1
fi

echo "------------------- sam-fsd information -------------" >>$REPORT
verbose /usr/lib/fs/samfs/sam-fsd -v

echo "------------------- filesystem information ----------" >>$REPORT
# Background this command so it doesn't hang the script
# on file system problems.
echo ""     >>$REPORT 2>&1
echo "    " $PROMPT /bin/df -kl >>$REPORT 2>&1
/bin/df -kl > /tmp/$$.bg.out 2>&1 &
sleep 5
twiddle
sleep 5
if [ -s /tmp/$$.bg.out ]; then
    cat /tmp/$$.bg.out | sed -e "s/^/     /"  >>$REPORT 2>&1
else
    echo "     $TAG /bin/df -kl timed out" >>$REPORT 2>&1
fi
echo ""     >>$REPORT 2>&1
rm -f /tmp/$$.bg.out

verbosei /etc/mount 

showifiles /etc/mnttab /etc/vfstab /etc/dfs/dfstab /etc/inittab

# accumulate samfs filesystem mount points
SAMFSMP=`sed -e "/#/s/#.*//" < /etc/vfstab | /bin/awk '$4 == "samfs" { print $3 " "}'`

# accumulate samfs filesystem names
SAMFSES=`sed -e "/#/s/#.*//" < /etc/vfstab | /bin/awk '$4 == "samfs" { print $1 " "}'`

echo "------------------- filesystem inodes ---------------" >>$REPORT
# Background this command so it doesn't hang the script
# on file system problems.
for dir in $SAMFSMP; do
    echo ""     >>$REPORT 2>&1
    echo $PROMPT /bin/ls -al $dir/.inodes >>$REPORT 2>&1
    /bin/ls -al $dir/.inodes > /tmp/$$.bg.out 2>&1 &
    sleep 5
    twiddle
    if [ -s /tmp/$$.bg.out ]; then
        cat /tmp/$$.bg.out >>$REPORT 2>&1
    else
        echo "$TAG /bin/ls -al $dir/.inodes timed out" >>$REPORT 2>&1
    fi
    echo ""     >>$REPORT 2>&1
    rm -f /tmp/$$.bg.out
done

echo "------------------- filesystem info -----------------" >>$REPORT
for fs in $SAMFSES; do
    verbose /opt/SUNWsamfs/sbin/samfsinfo $fs
done

echo "------------------- shared filesystem info ----------" >>$REPORT
for fs in $SAMFSES; do
    if [ `mount -v | grep "type samfs" | cut -d" " -f1 | egrep -c "^$fs$"` -eq 0 ]; then
        verbose /opt/SUNWsamfs/sbin/samsharefs -R $fs
    else
        verbose /opt/SUNWsamfs/sbin/samsharefs $fs
    fi
done

echo "------------------- filesystem parameters -----------" >>$REPORT
for SAMFS in $SAMFSMP; do
    verbose /opt/SUNWsamfs/sbin/samcmd N $SAMFS
done

echo ""   >>$REPORT 2>&1
echo "------------------- samu filesystems info -----------" >>$REPORT
verbose /opt/SUNWsamfs/sbin/samcmd f

echo "------------------- samu daemon trace info ----------" >>$REPORT
verbose /opt/SUNWsamfs/sbin/samcmd d

echo "------------------- samu mass storage info ----------" >>$REPORT
verbose /opt/SUNWsamfs/sbin/samcmd m

echo "------------------- samu active services ------------" >>$REPORT
verbose /opt/SUNWsamfs/sbin/samcmd P

echo "------------------- samu device status info ---------" >>$REPORT
verbose /opt/SUNWsamfs/sbin/samcmd s

echo "------------------- samu removable media info -------" >>$REPORT
verbose /opt/SUNWsamfs/sbin/samcmd r

echo "------------------- samu preview info ---------------" >>$REPORT
verbose /opt/SUNWsamfs/sbin/samcmd p

echo "------------------- samu pending stage queue --------" >>$REPORT
verbose /opt/SUNWsamfs/sbin/samcmd w

echo "------------------- samu staging queue info ---------" >>$REPORT
verbosehead /opt/SUNWsamfs/sbin/samcmd u

echo "------------------- samu staging activity info ------" >>$REPORT
verbose /opt/SUNWsamfs/sbin/samcmd n

echo "------------------- samu archiver info --------------" >>$REPORT
for SAMFS in $SAMFSES; do
    verbose /opt/SUNWsamfs/sbin/samcmd a $SAMFS
done

echo "------------------- archiver -lv --------------------" >>$REPORT
echo ""   >>$REPORT 2>&1
verbose /bin/grep wait $ETCDIR/archiver.cmd
verbose /opt/SUNWsamfs/sbin/archiver -lv
echo ""   >>$REPORT 2>&1

echo "------------------- showqueue -v --------------------" >>$REPORT
echo "" > /tmp/$$.showqueue 2>&1
echo $PROMPT /opt/SUNWsamfs/sbin/showqueue -v >> /tmp/$$.showqueue 2>&1
echo "" >> /tmp/$$.showqueue 2>&1
/opt/SUNWsamfs/sbin/showqueue -v >> /tmp/$$.showqueue 2>&1
if [ -r /tmp/$$.showqueue ]; then
	head -$SHOWQUEUE_LINES /tmp/$$.showqueue >>$REPORT 2>&1
	TARN=`/bin/wc /tmp/$$.showqueue | cut -c1-8`
	rm -f ${REPORTDIR}/${REPORTNAME}.a_showqueue.Z
	if [  $TARN -gt $SHOWQUEUE_LINES ]; then
		echo ""   >>$REPORT 2>&1
		echo ""   >>$REPORT 2>&1
		echo "showqueue output truncated..." >>$REPORT 2>&1
		# Save complete archiver showqueue file for ftp
		compress /tmp/$$.showqueue
		mv /tmp/$$.showqueue.Z ${REPORTDIR}/${REPORTNAME}.a_showqueue.Z
	fi
	rm -f /tmp/$$.showqueue
	echo ""   >>$REPORT 2>&1
else
	echo $TAG Something is wrong in showqueue >>$REPORT 2>&1
fi

echo "------------------- kernel statistics ---------------" >>$REPORT
verbose /opt/SUNWsamfs/sbin/samcmd K

echo "------------------- disk archiving dictionary ------" >>$REPORT
verbose /opt/SUNWsamfs/sbin/samcmd D

echo "------------------- ps -edalf -----------------------" >>$REPORT
verbose /bin/ps -edalf

echo "------------------- iostat --------------------------" >>$REPORT
verbose "/bin/iostat -en | grep -v ' nfs'"

echo "------------------- mpstat --------------------------" >>$REPORT
verbose "/bin/mpstat"

echo "------------------- kstat ---------------------------" >>$REPORT
verbose "/bin/kstat -n cpu_info0"

echo "------------------- prstat --------------------------" >>$REPORT
verbose /bin/prstat 1 1

echo "------------------- prtconf -------------------------" >>$REPORT
verbose /usr/sbin/prtconf -V
verbose /usr/sbin/prtconf

echo "------------------- shared memory -------------------" >>$REPORT
verbose /opt/SUNWsamfs/sbin/dmpshm

echo "------------------- archiver datadir ----------------" >>$REPORT
verbose /bin/ls -ld $VARDIR/archiver
verbose /bin/ls -lLd $VARDIR/archiver
verbose /bin/ls -lLa $VARDIR/archiver
verbose /bin/ls -ld $ARCHDATA
verbose /bin/ls -lLd $ARCHDATA
verbose /bin/ls -lLa $ARCHDATA

if [ -d $ARCHDATA ]; then
  if [ -r $ARCHDATA -a -x $ARCHDATA ]; then
	(
		cd $ARCHDATA
		find . \( -name "*core*" -o -name "*log*" \) -print > /tmp/$$.exclude
		tar cfX /tmp/$$.tar /tmp/$$.exclude .
		compress /tmp/$$.tar
	) >>$REPORT 2>&1
	if [ -r /tmp/$$.tar.Z ]; then
		uuencode archive.tar.Z </tmp/$$.tar.Z > /tmp/$$.tarz
		head -$DATA_DIR_LINES /tmp/$$.tarz >>$REPORT 2>&1
		TARN=`/bin/wc /tmp/$$.tarz | cut -c1-8`
		rm -f ${REPORTDIR}/${REPORTNAME}.a_data.tar.Z
		if [  $TARN -gt $DATA_DIR_LINES ]; then
			echo ""   >>$REPORT 2>&1
			echo ""   >>$REPORT 2>&1
			echo "end" >>$REPORT 2>&1
			# Save complete archiver data tar file for ftp
			mv /tmp/$$.tar.Z ${REPORTDIR}/${REPORTNAME}.a_data.tar.Z
		fi
		rm -f /tmp/$$.exclude /tmp/$$.tar.Z /tmp/$$.tarz
	else
		echo $TAG Something is wrong in $ARCHDATA >>$REPORT 2>&1
	fi
  else
	rerun_as_root $ARCHDATA
  fi
fi

echo "------------------- stager datadir ----------------" >>$REPORT
verbose /bin/ls -ld $STAGER_DATA
verbose /bin/ls -lLd $STAGER_DATA
verbose /bin/ls -lLa $STAGER_DATA

if [ -d $STAGER_DATA ]; then
  if [ -r $STAGER_DATA -a -x $STAGER_DATA ]; then
	(
		cd $STAGER_DATA
		find . \( -name "*core*" -o -name "*log*" \) -print > /tmp/$$.exclude
		tar cfX /tmp/$$.tar /tmp/$$.exclude .
		compress /tmp/$$.tar
	) >>$REPORT 2>&1
	if [ -r /tmp/$$.tar.Z ]; then
		uuencode stager.tar.Z </tmp/$$.tar.Z > /tmp/$$.tarz
		head -$DATA_DIR_LINES /tmp/$$.tarz >>$REPORT 2>&1
		TARN=`/bin/wc /tmp/$$.tarz | cut -c1-8`
		rm -f ${REPORTDIR}/${REPORTNAME}.s_data.tar.Z
		if [  $TARN -gt $DATA_DIR_LINES ]; then
			echo ""   >>$REPORT 2>&1
			echo ""   >>$REPORT 2>&1
			echo "end" >>$REPORT 2>&1
			# Save complete stager data tar file for ftp
			mv /tmp/$$.tar.Z ${REPORTDIR}/${REPORTNAME}.s_data.tar.Z
		fi
		rm -f /tmp/$$.exclude /tmp/$$.tar.Z /tmp/$$.tarz
	else
		echo $TAG Something is wrong in $STAGER_DATA >>$REPORT 2>&1
	fi
  else
	rerun_as_root $STAGER_DATA
  fi
fi

echo "------------------- dump_log ------------------------" >>$REPORT
verbose /bin/ls -l /var/adm/log/fs*log
echo /opt/SUNWsamfs/sbin/dump_log >>$REPORT 2>&1 
/opt/SUNWsamfs/sbin/dump_log >>$REPORT 2>&1

echo "------------------- core files ----------------------" >>$REPORT
echo "" >>$REPORT 2>&1

ONLINE_CORE_FILES=""
for DIR in $ETCDIR $VARDIR $USERDIR $EXECDIR; do

    CORE_FILES=""
    if [ -d $DIR ]; then
        if [ -r $DIR -a -x $DIR ]; then
            echo "CORE_FILES=/bin/find $DIR -follow -name \"core*\" -type f -print" >>$REPORT
            CORE_FILES=`/bin/find $DIR -follow -name "core*" -type f -print` 
            for file in $CORE_FILES; do
                verbose "/bin/ls -tlLd $file; /bin/file $file"
            done
        else
            rerun_as_root $DIR
        fi
    else
        echo $TAG missing $DIR >>$REPORT 2>&1
    fi

    if [ x"$CORE_FILES" != x ]; then
        ONLINE_CORE_FILES="$ONLINE_CORE_FILES $CORE_FILES"
    else
        echo "" >>$REPORT 2>&1
    fi

done

if [ -f /core ]; then
    verbose "/bin/ls -tlLd /core; /bin/file /core"
    ONLINE_CORE_FILES="$ONLINE_CORE_FILES /core"
fi

echo "------------------- core file stack tracebacks ------" >>$REPORT
if [ $UID -eq 0 ]; then
	for CORE in $ONLINE_CORE_FILES; do
		verbose "/bin/pstack $CORE; /bin/pflags $CORE"
	done
else
	rerun_as_root pstack
fi

echo "------------------- system panic dumps --------------" >>$REPORT
if [ $UID -eq 0 ]; then
	verbose /usr/sbin/dumpadm 
	dumpdir=`/usr/sbin/dumpadm | grep "core dir" | sed -e "s/Savecore directory: //" | /bin/awk '{print $1}'`
	enabled=`/usr/sbin/dumpadm | grep "core ena" | sed -e "s/Savecore enabled: //" | /bin/awk '{print $1}'`
	if [ -n "$enabled" ]; then
		if [ $enabled = "no" ]; then
			echo $TAG Core dump program \'savecore\' disabled by /usr/sbin/dumpadm >>$REPORT
		fi
	fi
else
	rerun_as_root dumpadm
fi

if [ -n "$dumpdir" ]; then
	coredir=`eval echo $dumpdir`
	verbose /bin/ls -ld $coredir
	verbose /bin/ls -l $coredir
	for unix in `ls $coredir/unix.[0-9]* 2>/dev/null`
	do
		twiddle
		vmcore=`echo $unix | sed -e "s./unix./vmcore."`
		verbose /bin/ls -l $unix $vmcore
		verbose /bin/file $unix $vmcore
		VM_SOL_VER=`/bin/file $vmcore | cut -d" " -f2`
		# Only process vmcores that match the running Solaris release.
		if [ $SOL_VER = $VM_SOL_VER ]; then
			if [ $SOL_VER = "5.9" ]; then
				echo '=n"---- date/time ----"
					time/y
					lbolt/K
					=n"---- utsname ----"
					$<utsname
					=n"---- sam_version/sam_build_uname ----"
					sam_version/s
					sam_build_uname/s
					=n"---- panic string ----"
					*panicstr/s
					=n"----panic_regs/2K----"
					panic_regs/2K
					=n"---- stack traceback ----"
					$c
					=n"---- stack traceback verbose----"
					$C
					=n"---- message buffer ----"
					$<msgbuf
					=n"---- threadlist ----"
					$<threadlist
					=n"---- sam_ mdb end ----"' | mdb -k $unix $vmcore 2>&1 | head -$MDB_LINES >>$REPORT 2>&1
			else
				echo '=n"---- date/time ----"
					time/y
					lbolt/K
					=n"---- utsname ----"
					utsname::print
					=n"---- sam_version/sam_build_uname ----"
					sam_version/s
					sam_build_uname/s
					=n"---- panic string ----"
					*panicstr/s
					=n"----panic_regs/2K----"
					panic_regs/2K
					=n"---- stack traceback ----"
					$c
					=n"---- stack traceback verbose----"
					$C
					=n"---- message buffer ----"
					$<msgbuf
					=n"---- threadlist ----"
					::threadlist -v
					=n"---- function call args ----"
					::walk thread | ::findstack ".$c6"
					=n"---- sam_ mdb end ----"' | mdb -k $unix $vmcore 2>&1 | head -$MDB_LINES >>$REPORT 2>&1
			fi
		fi
	done
fi

echo "" >>$REPORT 2>&1
echo "End at `/bin/date` on `/bin/uname -n` by `/bin/id`" >>$REPORT
echo " " >>$REPORT
echo "------------------- THE END -------------------------" >>$REPORT
chmod 444 $REPORT
echo " "
echo " "
echo "The report in $REPORT should now be ftp'ed to your"
echo "support provider as a binary file.  If you need to compress"
echo "the file, use only the standard Solaris compress(1) utility."
echo " "
if [ -s ${REPORTDIR}/${REPORTNAME}.a_showqueue.Z ]; then
    echo "This script created a separate archiver showqueue file.  Please ftp"
    echo "the following file to your support provider as a binary file."
    echo " "
    echo "${REPORTDIR}/${REPORTNAME}.a_showqueue.Z"
    echo " "
fi
if [ -s ${REPORTDIR}/${REPORTNAME}.a_data.tar.Z ]; then
    echo "This script created a separate archiver data file.  Please ftp"
    echo "the following file to your support provider as a binary file."
    echo " "
    echo "${REPORTDIR}/${REPORTNAME}.a_data.tar.Z"
    echo " "
fi
if [ -s ${REPORTDIR}/${REPORTNAME}.s_data.tar.Z ]; then
    echo "This script created a separate stager data file.  Please ftp"
    echo "the following file to your support provider as a binary file."
    echo " "
    echo "${REPORTDIR}/${REPORTNAME}.s_data.tar.Z"
    echo " "
fi
if [ -s /var/tmp/fsmgr.overall.log ]; then
    echo "This script created a separate SAM-QFS Manager data file.  Please"
    echo "ftp the following file to your support provider as a binary file."
    echo " "
    echo "/var/tmp/fsmgr.overall.log"
    echo " "
fi
if [ x"$ONLINE_CORE_FILES" != x ]; then
    echo "This script found the following core files.  Please ftp them as"
    echo "binary files to your support provider only if they appear to be"
    echo "from the SAM-QFS products."
    echo " "
    for file in $ONLINE_CORE_FILES; do
        /bin/file $file | sed -e "s/:.*,/ :/" ; /bin/ls -tlLd $file
        echo
    done
fi
