#! /bin/ksh
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# bos72X src/bos/usr/sbin/snap/snap.sh 1.53.25.54 
#  
# Licensed Materials - Property of IBM 
#  
# Restricted Materials of IBM 
#  
# COPYRIGHT International Business Machines Corp. 2020,2021 
# All Rights Reserved 
#  
# US Government Users Restricted Rights - Use, duplication or 
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp. 
#  
# IBM_PROLOG_END_TAG 
# @(#)63	1.53.25.45  src/bos/usr/sbin/snap/snap.sh, cmdsnap, bos72Q, q2019_25A4 6/13/19 02:45:26
# COMPONENT_NAME: (cmdsnap) SNAP Determination Tool
#
# FUNCTIONS: snap.sh

##
# WARNING!  If you add a file or directory to the destdir path,
# be sure to include it in the dflist in state_func104.
#
# Info: Exit code more than 100 is used for VIOS CLI. Consult their code
# [snap cli command] before using exit code more than 100
##

#
# Set the LC_MESSAGES and LC_TIME variables to C.  Snap only works
# for the C locale.  It's not internationalized.
#
export LC_MESSAGES=C
export LC_TIME=C
export LC_NUMERIC=C
export LC_CTYPE=C

PATH=/usr/bin:/etc:/usr/sbin:/usr/ucb:/usr/bin/X11:/sbin:$PATH
/usr/bin/ckauth aix.system.stat
if [ $? != 0 ]
then
	echo "snap: Only users with aix.system.stat authorization can run snap command"
	exit 1 
fi

ulimit -f unlimited

#
# Define external commands.
#

#
# Define constants
#
bootinfo=/usr/sbin/bootinfo     # Boot information command


#
# Define variable defaults.
#
devtype=""              # Default device type
destdir=/tmp/ibmsupt    # Default destination directory
device=n                # Device required arg
action=n                # Action flag required arg
state=""
memsize="$bootinfo -r"  # Determine real memory size
complist="async dump dump/autoload filesys general general/nim kernel lang liveupdate printer XS25 sna tcpip install ssa scraid lvm wlm wpars hacmp pcixscsi sissas ctsupt products flash IB history"
dirlist_all="$complist testcase other"
scriptlist=""           # snap scripts to run
# snap scripts to run with -a flag
scriptlista="client_collectall vfc_client_collectall getRtasHeap nfsall dumpdata artex caa cache_mgt_collect pfc_collect vnicCollect nvme_collect scsidisk_collect dpcom_collect"
# snap scripts to run with -g flag
scriptlistg="client_collectall vfc_client_collectall nvme_collect scsidisk_collect dpcom_collect"

# snap scripts to run under vios for -a and -g flags.
scriptlista_vios="svCollectall lsvirt poolfs"
scriptlistg_vios="svCollectall"
snap_vios=n
vioscli=/usr/ios/cli/ioscli 	# VIOS CLI path

# livedump data script
dumpdatascript="dumpdata"

total_bytes=0    # Initialize space byte counter
sleep_time=5            # Sleep time before waking up to check netcmds
netcmdlist="df enq netstat arp rpcinfo exportfs"
			# List of commands that may hang on the network so that
			# we can handle them differently
typeset -lL1 dodmpcpy   # Define variable as one lowercase char, left-justified
compressed_dump_file="" # Destination compressed file
compress_header=""	# Indicates compression status
			# 	"" - no compress
			# 	"1" compress header at start of the first block
			# 	"2" compress header at start of the second block

file_cnt=0		# number cpufiles in a multi cpu trace
file_lst=""		# name of multi cpu files
nodenames=""
initsetup_done=n
splitsize=0             # define variable for component split size for snap split
doneparsingargs=n       # indicates whether arguments are parsed
scriptarg=n             # indicates if script passed as argument
allarg=n                # indicates if All passed as argument
filearg=n               # indicates if file of script names passed as argument 
mutualexclusion=y       # only one of script, All and file name detected on cmd line
# directory where scripts need to be executable
scriptrepos="/usr/lib/ras/snapscripts"
clusterwide=n           # Are we Collecting snap data across cluster nodes
nodumpcollect=n
#
# Define default files.
#
kernel=/unix
trcfile=/var/adm/ras/trcfile				# default trace file name 
lvupETCBase=/etc/liveupdate                             # Base path of LKU etc files 
lvupLogBase=/var/adm/ras/liveupdate                     # Liveudate log files 
hmcauthlogFile=/var/adm/ras/hmcauth.log                 # hmcauth log for liveupdate operation
pvcauthlogFile=/var/adm/ras/pvcauth.log                 # pvcauth log for liveupdate operation
# User and shell history collected from following users
# By default it is only root. When -u is specified we replace this.
userList="root"

#
# Set flags.
#
doall=n                 # Gather all
dogen=n                 # Gather general
dopred=n		# Include Pd* ODM database files in general info
dotcp=n                 # Gather tcpip
donfs=n                 # Gather nfs 
dokern=n                # Gather kernel
doprt=n                 # Gather printer
dodump=n                # Gather dump and /unix
doadump=n		# Automated Dump Analysis
dosna=n                 # Gather sna
dosec=n			# Include security files in general information
dofs=n			# Gather file system 
doasync=n               # Gather async (tty)
dolang=n                # Gather lang info 
doXS25=n		# Gather X.25 LPP info
doIB=n			# Gather InfiniBand configuration and debug information
doinst=n		# Gather install info
dossa=n			# Gather SSA info
doscraid=n		# Gather SCRAID info
dolvm=n			# Gather LVM
dotar=n                 # Create snap.*pax.Z* file(s)
dodev=n                 # Put snap.*pax.Z* onto diskette or tape
doclean=n               # Remove snap gathered files
doview=n		# View component snap files
badargs=n		# Flag for other args with view option
docheck=y		# Flag to check for free space
doscript=n		# Flag to call third-party scripts
doscripta=n		# Flag to call third-party scripst with -a flag
doscriptg=n		# Flag to call third-party scripst with -g flag
dosplit=n               # Flag to enable splitting of output file
domtrace=n              # Flag to copy multicpu files
dowlm=n			# Falg to Collect wlm data
dohw=n			# Falg to Collect Hardware data
doscanonly=n		# Flag to Collect scanout/checkstop files only.
scanfiles=		# platform or scan file list.
dogenoscan=n		# Don't include scanout files in general.
dohacmp=n               # Flag to Collect HACMP Information.
domflag=n               # Flag to send nodenames to clsnap.
dopcixscsi=n            # Gather PCI-X-SCSI info.
dosissas=n              # Gather SISSAS info.
dowpars=n		# Gather wpars info
dodumpdata=n		# Gather livedump info.
dozflag=n		# -z flag is set.
dohist=n                # Collect user shell and SMIT history information
dolku=n                 # flag to copy live kernel update files
print_usage=y		# VIOS snap command can pass E flag to 
			# signify that we do not have to print usage
			# by default we are goint to print it
doflash=n		# Gather Flash adapter related information.
doper=n			#Gather ptools topas file
#Global variables for -z flag
zadd=n			#-z flag used with ADD
zdel=n			#-z flag used with DELETE
zrun=n			#-z flag used to run debug commands.
zall=n			#-z ALL
cmdtimeout=300		#Default timeout for -z is 300 secs
export SNAPDEBUGDATA=""		#Env variable to set the name of the products for which debug commands has been run.
SKIP_PRODUCTS=""		#Stores the list of products for which command execution should be skipped.
Z_OLD_ODMDIR=""		#Tmp to save value of ODMDIR
Z_ODMDIR="/usr/lib/objrepos"


#Temp files used by -z flag
z_temp_dir="/usr/lib/ras/snapscripts/tmp/"
zadd_temp_file="/usr/lib/ras/snapscripts/tmp/.snap.$$.zadd"	#Used to save details about product registeration
zdel_temp_file="/usr/lib/ras/snapscripts/tmp/.snap.$$.zdel"	#Details about deregisteration.
zrun_temp_file="/usr/lib/ras/snapscripts/tmp/.snap.$$.zrun"	#Details about products for which debug commands will be executed.

zget_temp_file="/usr/lib/ras/snapscripts/tmp/.snap.$$.zget"
zall_temp_file="/usr/lib/ras/snapscripts/tmp/.snap.$$.zall"
zrun_exec_file="/usr/lib/ras/snapscripts/tmp/.snap.$$.zexec"
zrun_exec_class_file="/usr/lib/ras/snapscripts/tmp/.snap.$$.zexec_class"

#
# Working functions
#

# Function: intr_action
intr_action () {
	echo " \n\nYou have chosen to interrupt the current process."
	echo "Press 'enter' for no action, 's' to attempt to kill"
	echo "the current operation, or 'q' to quit out altogether: \c"
	read response

	if [ "$response" = q -o "$response" = Q ]
	then
		exit 10
	else
		if [ "$response" = s -o "$response" = S ]
		then
			cmdtokill=`echo $cmd | awk '{print $1}'`
			pids=`ps -ef | fgrep $cmdtokill | fgrep -v fgrep | awk '{print $2}'`
			numpids=`echo $pids | awk '{print NF}'`
			if [ "$numpids" = 1 ]
			then
				echo "\nKilling process '$cmdtokill' with a process id of $pids...\c"
				kill -9 $pids >/dev/null 2>&1
			else
				counter=1
				gotit=n
				while [ "$counter" -le "$numpids" ]
				do
					pid=`echo $pids | cut -d' ' -f$counter`
					ppid=`ps -ef | fgrep $pid | fgrep -v fgrep | awk '{print $3}'`
					ps -ef | fgrep $ppid | fgrep -v fgrep | fgrep snap >/dev/null 2>&1
					if [ "$?" = 0 ]
					then
						echo "\nKilling process '$cmdtokill' with a process id of $pid...\c"
						gotit=y
						kill -9 $pid >/dev/null 2>&1
						echo " done.\n"
						return
					fi
					((counter += 1))
				done
				[ "$gotit" = n ] && echo " \nProcess '$cmdtokill' has already exited... continuing."
			fi
		else
			echo "\nNo action taken, skipping current pass.... continuing"
			return
		fi
	fi
} # End of intr_action


# Function: ckspace
ckspace () {
# $1 = how much free space is needed
#
#
	total_bytes=`expr $total_bytes / 1024`
	tempdir=$destdir
	while [ "$tempdir" != "" ]
	do

	df -k $tempdir >/dev/null 2>&1
	if [ "$?" = 0 ]
	then
		cmd="df -k"
		freespace=`df -k $tempdir` 
		freespace=`echo $freespace | awk '{print $11}'`
		if [ "$freespace" -lt "$total_bytes" ]
		then
			echo " \n\nsnap: not enough space in $tempdir, free space is $freespace kbytes,"
			echo "       $total_bytes kbytes are needed.  Please correct and retry."
			exit 11
		else
			echo " done."
			return;
		fi
	else
		numpaths=`echo $tempdir | awk -F/ '{print NF}'`
 		count=2
		newdir=
		while [ "$count" != "$numpaths" ]
		do
			atom=/`echo $tempdir | cut -d/ -f$count`
			newdir=$newdir$atom
			count=`expr $count + 1`
		done
		tempdir=$newdir
	fi
	done

}  # End ckspace



# Function valid_dir
valid_dir () {
#
#
case "$1" in
        /*      )     echo "Destination directory set to $1"
                        ;;
        * )             echo "Invalid -d argument.  You must specify an absolute path."
                        exit 12
                        ;;          # Not valid path.     
esac

} # End of valid_dir


# Function valid_dev
valid_dev () {
#
#
case "$1" in
        /dev/rmt* )     echo "\nSetting output device to $1...\c"
			bsname=`basename $1 | awk -F . '{print $1}'`
			blksz=`lsattr -l $bsname -a "block_size" -F value` > /dev/null 2>&1
			if [ "$?" != 0 ]
			then
				exit 99
			fi
			tape=y
			echo " done."
                        ;;
        /dev/cd* )     echo "\nSetting output device to $1...\c"
			blksz=64k
			echo " done."
                        ;;
        /dev/rcd* )	echo "\nSetting output device to $1...\c"
			blksz=64k
			echo " done."
                        ;;
        * )             echo "Invalid output device.\nValid devices are: \c"
                        echo "tape drives, \c"
                        echo "DVD RAM drives "
                        exit 13
                        ;;          # Not output device
esac

} # End of valid_dev


# Function valid_idev
# Read in name of input device for external dump copy
valid_idev () {
#
#
deftapedev=/dev/rmt0
while :
do
	echo "\nPlease enter external device(default $deftapedev):  \c"
	read tapedev
	if [ -z "$tapedev" ]
	then
		tapedev=$deftapedev
	fi
	case "$tapedev" in
        	/dev/rmt* )     echo "\nSetting input device to $tapedev...\c"
				btapedev=`basename $tapedev`
				is_this_tape_device $btapedev
				if [ "$istapdev" -eq 1 ]
				then
					echo " done."
					return
				else
					echo "\nNot a Valid tape device."
				fi
				;;
        	/dev/rcd* )     echo "\nSetting input device to $tapedev...\c"
				btapedev=`basename $tapedev`
				is_this_cdrom_device $btapedev
				if [ "$iscdrdev" -eq 1 ]
				then
					echo " done."
					return
				else
					echo "\nNot a Valid DVD or CD device."
				fi
                        	;;
        	/dev/cd* )     echo "\nSetting input device to $tapedev...\c"
				btapedev=`basename $tapedev`
				is_this_cdrom_device $btapedev
				if [ "$iscdrdev" -eq 1 ]
				then
					echo " done."
					return
				else
					echo "\nNot a Valid DVD or CD device."
				fi
                        	;;
        	* )             echo "Invalid input device.\nValid devices are: \c"
                        	echo "tape drives, \c"
                        	echo "DVD or CD drives "
                        	;;          # Not input device
	esac
done

} # End of valid_idev

################################################################################
#
# NAME:    valid_users
#
# PURPOSE:
#          Check if all comma seperated users
#          specified are present on the system.
#
# INPUT:   Comma seperated usernames whose history is being collected
#
# ERROR:   Snap exits if list of users specified are not valid
#
################################################################################
valid_users() {
  # Sanity check for number of arguments
  if [[ $# -ne 1 ]]; then
    echo "snap: List of users not specified"
    exit 1
  fi

  # Convert comma seperated usernames to a 'for' iterable variable
  argUserList=`echo "$1" | tr "," " " | uniq 2>/dev/null`
  if [[ -z "$argUserList" ]]; then
    echo "snap: List of users passed not formatted correctly"
    exit 1
  fi

  # Find all the users on the system
  userListFile="/etc/passwd"
  systemUserList=`cat $userListFile | awk '{ print $1}' 2>/dev/null`
  if [[ -z "$systemUserList" ]]; then
    echo "snap: List of users on system is corrupt"
    exit 1
  fi

  # Search for users in the system user list, one by one
  for thisUser in $argUserList; do
    echo $systemUserList | grep $thisUser 1>/dev/null 2>&1
    if [[ $? -ne 0 ]]; then
      echo "snap: User $thisUser not found on the system"
      exit 1
    fi
  done

  # Copy this iterable variable back into userList for future use
  userList=$argUserList
}
# End of valid_users


# Function: Initial setup.
initial_setup () {

[ "$initsetup_done" = y ] && return

# Create the directory tree that will hold the gathered information

echo "********Checking and initializing directory structure"
if [ ! -d "$destdir" ]
then
        echo "Creating $destdir directory tree...\c"
        mkdir $destdir  > /dev/null 2>&1  
	echo " done."
fi

# We already know that we're running as root so make sure that destdir
# is owned by root (process' effuid) and that destdir is still a
# directory.

# In RBAC environment the user has to be either authorized or be root user 
#to be able use the destdir.
AUTH=`/usr/bin/ckauth aix.system.stat`

[[ ( -O $destdir || $AUTH -eq 0 ) && ! -L $destdir && -d $destdir ]] || {
	print -u2 "${0##*/}: could not create directory tree \"$destdir\""
	exit 1
}

dirlist="testcase other"
[ "$doall" = y ] && dirlist=$dirlist_all
[ "$dogen" = y ] && dirlist="general general/diagnostics general/nim pcixscsi sissas $dirlist"
[ "$domtrace" = y ] && dirlist="general $dirlist"
[ "$dotcp" = y ] && dirlist="tcpip $dirlist"
[ "$donfs" = y ] && dirlist="nfs $dirlist"
[ "$dokern" = y ] && dirlist="kernel $dirlist"
[ "$doprt" = y ] && dirlist="printer $dirlist"
[ "$dodump" = y ] && dirlist="dump dump/autoload $dirlist"
[ "$dosna" = y ] && dirlist="sna $dirlist"
[ "$dofs" = y ] && dirlist="filesys $dirlist"
[ "$doasync" = y ] && dirlist="async $dirlist"
[ "$dolang" = y ] && dirlist="lang $dirlist"
[ "$doXS25" = y ] && dirlist="XS25 $dirlist"
[ "$doIB" = y ] && dirlist="IB $dirlist"
[ "$doinst" = y ] && dirlist="install $dirlist"
[ "$dossa" = y ] && dirlist="ssa $dirlist"
[ "$doscraid" = y ] && dirlist="scraid $dirlist"
[ "$dolvm" = y ] && dirlist="lvm $dirlist"
[ "$dowlm" = y ] && dirlist="wlm $dirlist"
[ "$dogenoscan" = y ] && dirlist="general pcixscsi sissas $dirlist"
[ "$doscanonly" = y ] && dirlist="general $dirlist"
[ "$dohacmp" = y ] && dirlist="hacmp $dirlist"
[ "$doscript" = y ] && dirlist="$scriptlist $dirlist"
[ "$doscripta" = y ] && dirlist="client_collect vfc_client_collect getRtasHeap nfs dumpdata artex caa cache_mgt_collect pfc_collect vnicCollect nvme_collect scsidisk_collect dpcom_collect $dirlist"
[ "$doscripta" = y ] && [ "$snap_vios" = y ] && dirlist="svCollect lsvirt poolfs $dirlist"
[ "$doscriptg" = y ] && dirlist="client_collect vfc_client_collect nvme_collect scsidisk_collect dpcom_collect $dirlist"
[ "$doscriptg" = y ] && [ "$snap_vios" = y ] && dirlist="svCollect $dirlist"
[ "$dopcixscsi" = y ] && dirlist="pcixscsi $dirlist"
[ "$dosissas" = y ] && dirlist="sissas $dirlist"
[ "$dowpars" = y ] && dirlist="wpars $dirlist"
[ "$clusterwide" = y ] && dirlist="testcase other"
[ "$dodumpdata" = y ] && dirlist="dumpdata $dirlist"
[ "$dozflag" = y ] && dirlist="products $dirlist"
[ "$doflash" = y ] && dirlist="flash $dirlist"
[ "$dohist" = y ] && dirlist="history $dirlist"
[ "$dolku" = y ] && dirlist="liveupdate liveupdate/etc liveupdate/liveupdate $dirlist"
[ "$doper" = y ] && dirlist="perf $dirlist"
for i in $dirlist
do
	if [ ! -d "$destdir/$i" ]
	then
        	echo "Creating $destdir/$i directory tree...\c"
		mkdir $destdir/$i > /dev/null 2>&1
		echo " done."
	else
		echo "Directory $destdir/$i already exists... skipping"
	fi
done


initsetup_done=y

echo "********Finished setting up directory $destdir\n"
}  # End of initial_setup()

# Function: interconfig 
interconfig () {
# 
# run the following here to bypass from run_cmd

netstat -ni | sed -n '2,$s/[* ].*//p' | uniq

}  # End of interconfig ()


######
# These functions must preceed run_cmd.
######

# sort ssa data by link, see state_func17 below.
ssa_linksort() {
    adap=$1
    for pdisk in $(lsdev -Csssar -cpdisk -Fname)
    do
      ssaconn -l $pdisk -a $adap 2>/dev/null
    done | sort -d +4 -5 +2 -3 2>&1
}


##############################################################################
# Function: run_cmd
#
# >>>>>>>IMPORTANT<<<<<<<<<>>>>>>>>>>IMPORTANT<<<<<<<<<>>>>>>>IMPORTANT<<<<<<<
# To utilize this facility and add new function to collect more data from a
# system you must use one of three methods to redirect the output
#
# 1) single redirection in the form of " > "
#     Notice the spaces surrounding the greater than sign
# 2) append redirection in the form of "  >> "
#     Notice the spaces surrounding the greater than signs
# 3) The copy command in the form if "cp -p file1 file2 file3 file4...destfile"
#     Notice the "cp -p" with a single space in between the letters
#
#   All of these forms are very important for supporting conversion of commands
#   to forms that will pipe their output to the "wc -c" command to count the
#   number of bytes for the particular operation.
#   If the commands are not in this form, you will get an error message.
#   Again, this is important to understand when adding new functionality into
#   the script for collecting more documentation
#
#   Each command that you would like to run must be in the form of a 3 line
#   sequence to perform the appropriate space checking.
#
#           string="lsdev -C"
#           cmd="lsdev -C >> $snapfile >/dev/null 2>&1"
#           run_cmd
#    
#    string  => This is the string that will be put into the various *.snap
#               files for the specified command.  This should match the command
#               that you actually want to run.  This string should be set to
#               null when output is not put into the *.snap file.
#    cmd     => This is the actual command you would like to run in one of the
#               three appropriate formats as noted above.  Notice the " >> " in
#               this form of the command.  This can be set to null if you just
#               want some informational output "string" in the *.snap file but
#               don't want to run any command.
#    run_cmd => This is just the call to this function to take appropriate 
#               action depending on which pass we are on.
#
#   If you are adding a command that needs to use network facilities at all 
#   and may hang when run, please add the command into the variable list
#   "netcmdlist" at the top of the file !!!
#
# >>>>>>>IMPORTANT<<<<<<<<<>>>>>>>>>>IMPORTANT<<<<<<<<<>>>>>>>IMPORTANT<<<<<<<
#
##############################################################################
#Note 1: Please follow the following guidelines while adding informational message with '*':
#1. Exclude \n from the double quotes when the message has '*' as that results in the expansion of * into the current directories
#2. Put 2 backslashes before \n as we process backslash twice so we need double the number to escape it twice

run_cmd() {
#
	cmdto_ck=`echo $cmd | sed 's/\( .*\)//'`
	netcmd=n
	for com in $netcmdlist
	do
		if [ "$com" = "$cmdto_ck" ]
		then
			netcmd=y
			break;
		fi
	done

	if [ "$passno" = 1 ]   # calculate total_bytes
	then
		# Section to convert commands in form of "lsdev -C >> $snapfile"
		echo "$cmd" | fgrep " >> " >/dev/null 2>&1
		if [ "$?" = 0 ]
		then

			exec 3>&2		#save stderr
			exec 2>/dev/null
			new_cmd=`echo $cmd | sed 's/\(.*\)\>\>.*/\1/'`
			new_cmd="$new_cmd | wc -c"
			if [ "$netcmd" = y ]
			then
				eval $new_cmd >/dev/null 2>&1 &
				pid=$!
				sleep $sleep_time
				ps -ef | fgrep $pid | fgrep -v fgrep >/dev/null 2>&1
				if [ "$?" = 0 ] 
				then
					echo " \n\nWARNING: Command '$cmdto_ck' is hanging due to an unresponsive server."
					echo "This will affect the filesystem requirement calculation and invalidate it."
					echo "If 'snap' fails due to lack of space it is due to this problem.\n"
				else
					temp_bytes=`eval $new_cmd`
					total_bytes=`expr $total_bytes + $temp_bytes`
				fi
			else
				# Not a net command.
				temp_bytes=`eval $new_cmd` 
				total_bytes=`expr $total_bytes + $temp_bytes`
			fi
			exec 2>&3		#restore stderr
			echo ".\c"
		else
			# Section to convert commands in form of "lsdev -C > $snapdir"
			echo "$cmd" | fgrep " > " >/dev/null 2>&1
			if [ "$?" = 0 ]
			then
				exec 3>&2
				exec 2>/dev/null
				new_cmd=`echo $cmd | sed 's/\(.*\)\>.*/\1/'`
                        	new_cmd="$new_cmd | wc -c"
				if [ "$netcmd" = y ]
				then
					eval $new_cmd >/dev/null 2>&1 &
					pid=$!
					sleep $sleep_time
					ps -ef | fgrep $pid | fgrep -v fgrep >/dev/null 2>&1
					if [ "$?" = 0 ] 
					then
						echo " \n\nWARNING: Command '$cmdto_ck' is hanging due to an unresponsive server.\n"
						echo "This will affect the filesystem requirement calculation and invalidate it."
						echo "If 'snap' fails due to lack of space it is due to this problem.\n"
					else
						temp_bytes=`eval $new_cmd`
						total_bytes=`expr $total_bytes + $temp_bytes`
					fi
				else
					# Not a net command
					temp_bytes=`eval $new_cmd` 
					total_bytes=`expr $total_bytes + $temp_bytes`
				fi

				exec 2>&3
                        	echo ".\c"
			else
				# Section to convert "cp -p" type commands
				echo "$cmd" | fgrep "cp -p" >/dev/null 2>&1
				if [ "$?" = 0 ]
				then
					exec 3>&2
					exec 2>/dev/null
					new_cmd=`echo $cmd | sed 's/\(.*\)\>.*/\
1/'`
					set $new_cmd
					numfields=$#
	
					cat_counter=3
					while [ "$cat_counter" -lt "$numfields" ]
					do
						file_to_cat=`echo $new_cmd | cut -d' ' -f$cat_counter`
       		                        	temp_bytes=`cat $file_to_cat | wc -c`
       		                        	total_bytes=`expr $total_bytes + $temp_bytes`
						cat_counter=`expr $cat_counter + 1`
					done
       		                       	echo ".\c"
					exec 2>&3
				else
					if [ "$cmd" != "" ]
					then
						echo ". failed."
						echo " \nsnap: invalid operation in function \"run_cmd\": \n\tcmd='$cmd'"
						echo "\tcomp='$comp'\n"
						exit 14
					fi
				fi
			fi
		fi


	else
		# Run the command, passno != 1.
		exec 3>&2
		exec 2>/dev/null
		if [ "$string" = "" ]
		then
			# No string specified, just run command
			if [ "$netcmd" = y ]
			then
				echo "$cmd" | fgrep " >> " >/dev/null 2>&1
				if [ "$?" = 0 ]
				then
					tempcmd=`echo $cmd | sed 's/\(.*\)\>\>.*
/\1/'`
					tempcmd="$tempcmd >/dev/null 2>&1"
				else
					echo "$cmd" | fgrep " > " >/dev/null 2>&1
					if [ "$?" = 0 ]
					then
						tempcmd=`echo $cmd | sed 's/\(.*
\)\>.*/\1/'`
						tempcmd="$tempcmd >/dev/null 2>&1"
					else
						tempcmd=cmd
					fi
				fi

				eval $tempcmd >/dev/null 2>&1 &
				pid=$!
				sleep $sleep_time
				ps -ef | fgrep $pid | fgrep -v fgrep >/dev/null 2>&1
				if [ "$?" = 0 ] 
				then
					echo " \n\nWARNING: Command '$cmdto_ck' is hanging due to an unresponsive server."
					echo "There will not be any 'snap' output for this command.\n"
					kill -9 $pid >/dev/null 2>&1
				else
					eval $cmd
					echo ".\c"
				fi
			else
				# Not a net command.
				eval $cmd
				echo ".\c"
			fi
		else
			# Put string in *.snap file and run command
			dots $snapfile "$string"
			if [ "$netcmd" = y ]
			then
				echo "$cmd" | fgrep " >> " >/dev/null 2>&1
				if [ "$?" = 0 ]
				then
					tempcmd=`echo $cmd | sed 's/\(.*\)\>\>.*
/\1/'`
					tempcmd="$tempcmd >/dev/null 2>&1"
				else
					echo "$cmd" | fgrep " > " >/dev/null 2>&1
					if [ "$?" = 0 ]
					then
						tempcmd=`echo $cmd | sed 's/\(.*
\)\>.*/\1/'`
						tempcmd="$tempcmd >/dev/null 2>&1"
					else
						tempcmd=cmd
					fi
				fi

				eval $tempcmd >/dev/null 2>&1 &
				pid=$!
				sleep $sleep_time
				ps -ef | fgrep $pid | fgrep -v fgrep >/dev/null 2>&1
				if [ "$?" = 0 ] 
				then
					echo " \n\nWARNING: Command '$cmdto_ck' is hanging due to an unresponsive server."
					echo "There will not be any 'snap' output for this command.\n"
					kill -9 $pid >/dev/null 2>&1
				else
					eval $cmd
					echo ".\c"
				fi
			else
				eval $cmd
				echo ".\c"
			fi
		fi
		exec 2>&3
	fi

} # End of run_cmd

# Function: dots
dots () {
#
        echo "\n....." >> $1  2>&1
        echo ".....    $2" >> $1  2>&1
        echo ".....\n" >> $1  2>&1

} # End of dots
        


#       State functions:
#
#               1. Gather general Information           -g
#               2. Gather tcpip information             -t
#               3. Gather nfs information               -n
#               4. Gather kernel information            -k
#               5. Gather printer information           -p
#               6. Gather dump and /unix                -D
#               7. Gather sna information               -s
#               8. Gather file system information       -f
#               9. Gather async (tty) information       -A
#               10. Gather programming lang information -l
#               11. Gather X.25 information		-X
#               12. Create snap.pax.Z file              -c
#               13. Put pax files to dskt or tape       -o
#               14. Cleanup files                       -r
#               16. Gather install information		-i
#               17. Gather SSA adapter/disk information -b
#               18. Gather LVM information              -L
#               19. Gather Multi-cpu information        -T
#               20. Gather wlm information              -w
#               22. Gather scraid information           -R
#		23. Gather wpars information            -@
#		24. -z flag [ADD/DEL/Run]		-z
#		25. Gather flash information            -F
#               50. Gather HACMP information            -e 
#               97. Gather User Shell and SMIT History  -u 
#               98. Gather Live update Information      -U
#		121. Gather PCI X SCSI information      -I
#		122. Gather PCI X SCSI information      -I
#               123. Gather InfiniBand Information      -Y
#
#       Action  |                                       |
#               |---------------------------------------|
#               |                       |               |
#       --------|-------|-------|-------|-------|-------|
#       dogen   | 1                     |               |
#       --------|-------|-------|-------|-------|-------|
#       dotcp   | 2                     |               |
#       --------|-------|-------|-------|-------|-------|
#       donfs   | 3                     |               |
#       --------|-------|-------|-------|-------|-------|
#       dokern  | 4                     |               |
#       --------|-------|-------|-------|-------|-------|
#       doprt   | 5                     |               |
#       --------|-------|-------|-------|-------|-------|
#       dodump  | 6                     |               |
#       --------|-------|-------|-------|-------|-------|
#       dosna   | 7                     |               |
#       --------|-------|-------|-------|-------|-------|
#       dofs    | 8                     |               |
#       --------|-------|-------|-------|-------|-------|
#       doasync | 9                     |               |
#       --------|-------|-------|-------|-------|-------|
#       dolang  | 10                    |               |
#       --------|-------|-------|-------|-------|-------|
#       doXS25  | 11                    |               |
#       --------|-------|-------|-------|-------|-------|
#       dotar   | 102                   |               |
#       --------|-------|-------|-------|-------|-------|
#       dodev   | 103                   |               |
#       --------|-------|-------|-------|-------|-------|
#       doclean | 104                   |               |
#       --------|-------|-------|-------|-------|-------|
#       doview  | 100                   |               |
#       --------|-------|-------|-------|-------|-------|
#       doinst  | 16                    |               |
#       --------|-------|-------|-------|-------|-------|
#       dossa   | 17                    |               |
#       --------|-------|-------|-------|-------|-------|
#       dolvm   | 18                    |               |
#       --------|-------|-------|-------|-------|-------|
#       domtrace| 19                    |               |
#       --------|-------|-------|-------|-------|-------|
#       dowlm   | 20                    |               |
#       --------|-------|-------|-------|-------|-------|
#       doscan  | 21                    |               |
#       --------|-------|-------|-------|-------|-------|
#       doscraid| 22                    |               |
#       --------|-------|-------|-------|-------|-------|
#     	dowpars | 23                    |               |
#       --------|-------|-------|-------|-------|-------|
#	dozflag | 24 					|
#       --------|-------|-------|-------|-------|-------|
#	doflash | 25                    |               |
#       --------|-------|-------|-------|-------|-------|
#       dohacmp | 50                    |               |
#       --------|-------|-------|-------|-------|-------|
#       dohist  | 97                    |               |
#       --------|-------|-------|-------|-------|-------|
#       dolku   | 98                    |               |
#       --------|-------|-------|-------|-------|-------|
#    dopcixscsi | 121   |       |       |       |       |       
#       --------|-------|-------|-------|-------|-------|
#    dosissas   | 122   |       |       |       |       |
#       --------|-------|-------|-------|-------|-------|
#       doIB    | 123                   |               |
#       --------|-------|-------|-------|-------|-------|
#	doper   | 26 					|
#       --------|-------|-------|-------|-------|-------|
#
# Begin defining state functions.
#

# Function state_func1
state_func1 () {
#            
# 

  comp=general
  snapfile=$destdir/$comp/$comp.snap
  snapdir=$destdir/$comp
  setfile=$destdir/$comp/survdump.settings
  diagdir=$destdir/$comp/diagnostics
  nimdir=$destdir/$comp/nim

  if [ "$dohw" = n ]
  then
    if [ -r /usr/lib/ras/cpufmt ]
    then
       file_lst=`trcrpt -t /usr/lib/ras/cpufmt $trcfile`

       file_cnt=`echo $file_lst| wc -w `
       if [ $file_cnt != 0 ]  && [ $passno = 1 ]  && [ "$domtrace" != y ] && [ "$doall" != y ]
       then
	  echo "\nWARNING: This is a multicpu trace. Specify -T flag to copy all CPU files. \n"
       fi
    fi
  fi


  if [ "$passno" = 1 ]
  then
  	echo "Checking space requirement for general information\c"
  else
  	echo "Gathering general system information\c"
  fi

  string="creation date"
  cmd="date > $snapfile 2>&1"
  run_cmd  

  #copy base trcfile
  string=""                                                                     
  cmd="cp -p $trcfile  $snapdir >/dev/null 2>&1"                     
  run_cmd

  #copy /etc/trcfmt file
  string=""
  cmd="cp -p /etc/trcfmt $snapdir >/dev/null 2>&1"
  run_cmd

  #copy output of trcnm command
  string="trcnm"
  cmd="trcnm > $snapdir/trcnm.out"
  run_cmd

  string="Diagnostic Files moved to $diagdir"
  cmd="cp -p /etc/lpp/diagnostics/data/diagrpt* $diagdir >/dev/null 2>&1"
  run_cmd

  if [ -x /usr/lib/boot/bin/dmpdt_chrp ]
  then
	string=""
	cmd="/usr/lib/boot/bin/dmpdt_chrp -i > $snapdir/devtree.out 2>&1"
	run_cmd
	cmd="/usr/lib/boot/bin/dmpdt_chrp -b > $snapdir/devtree.bin 2>&1"
        run_cmd
  fi

  if [ -x /usr/sbin/lsvpd ]
      then
      string=""
      cmd="lsvpd > $snapdir/lsvpd.out"
      run_cmd
  fi

  for j in `lsdev -C -F name | grep pci`
  do
        string="lsresource -al $j"
        cmd="lsresource -al $j >> $snapfile 2>&1"
        run_cmd
  done

  if [ -x /usr/sbin/lsslot ]
  then
        string="lsslot -c pci"
        cmd="lsslot -c pci >> $snapfile 2>&1"
	run_cmd
  fi

  if [ -x /usr/sbin/lsdev ]
  then
	string=""
	cmd="lsdev -Ccadapter -F \"name status location physloc description\" > $snapdir/lsdev.adapter"
	run_cmd

	string=""
	cmd="lsdev -Ccdisk -F \"name status location physloc description\" > $snapdir/lsdev.disk"
	run_cmd

	string=""
	cmd="lsdev -Cs scsi -F \"name status location physloc description\" > $snapdir/lsdev.scsi"
	run_cmd

        string="lsdev -Ccprocessor"
	cmd="lsdev -Ccprocessor >> $snapdir/processor.log"
        run_cmd

  fi 	


  if [ -x /usr/sbin/bindprocessor ]
  then
      string="bindprocessor -q"
      cmd="bindprocessor -q >> $snapdir/processor.log 2>&1"
      run_cmd
  fi

  if [ -x /usr/bin/errpt ]
  then
  	string=""
  	cmd="errpt -a > $snapdir/errpt.out 2>&1"
  	run_cmd
  fi

  if [ -x /usr/bin/lparstat ]
  then
	string=""
	cmd="/usr/bin/lparstat -i > $snapdir/lparstat.out 2>&1"
	run_cmd
  fi

  # Always gather the raw log file, def 349870.
  LOGFILE=`/usr/lib/errdemon -l |\
    awk '$0 ~ /^Log File/ {print $NF}'`
  if [[ -f "$LOGFILE" ]]
  then	# log file gotten. */
	string="Errlog file copied to $snapdir."
	cmd="cp -p $LOGFILE $snapdir/errlog >/dev/null 2>&1"
	run_cmd 
  fi

  # Get /etc/bosboot.sum, def 349870.
  if [[ -f /etc/bosboot.sum ]]
  then	# it exists.
	string="bosboot.sum file copied to $snapdir."
	cmd="cp -p /etc/bosboot.sum $snapdir >/dev/null 2>&1"
	run_cmd 
  fi

  if [ -e /etc/inittab ]
  then
  	string=""
  	cmd="cp -p /etc/inittab $snapdir > /dev/null 2>&1"
  	run_cmd
  fi

  string="env"
  cmd="env >> $snapfile 2>&1"
  run_cmd

  string="bootinfo -r"
  cmd="bootinfo -r >> $snapfile 2>&1"
  run_cmd

  # Gather the kernel's type, 349870.
  string="bootinfo -K"
  cmd="bootinfo -K >> $snapfile 2>&1"
  run_cmd

  string="lsps -a"
  cmd="lsps -a >> $snapfile 2>&1"
  run_cmd

  string=""
  cmd="oslevel -r > $snapdir/oslevel.info 2>&1"
  run_cmd

  string=""
  cmd="oslevel -s >> $snapdir/oslevel.info 2>&1"
  run_cmd

  string=""
  cmd="lslpp -hac > $snapdir/lslpp.hac 2>&1"
  run_cmd

  string=""
  cmd="instfix -i > $snapdir/instfix.i 2>&1"
  run_cmd

  string="lslpp -lc"
  cmd="lslpp -lc >> $snapfile 2>&1"
  run_cmd

  string="lslpp -La"
  cmd="lslpp -La >> $snapfile 2>&1"
  run_cmd

  # Show software installed by RPM
  if [ -x /usr/bin/rpm ]
  then
      string="rpm -qa"
      cmd="rpm -qa --queryformat '%{NAME}-%{VERSION}-%{RELEASE} %{INSTALLTIME:date}\n' | sort >> $snapfile 2>&1"
      run_cmd
  fi

  # Show software installed by System V 
  if [ -x /usr/sbin/pkginfo ]
  then
      string="pkginfo -l"
      cmd="pkginfo -l >> $snapfile 2>&1"
      run_cmd
  fi

  string=""
  cmd="alog -ot boot > $snapdir/alog.boot 2>&1"
  run_cmd 

  string=""
  cmd="alog -ot console > $snapdir/alog.console 2>&1"
  run_cmd

  string=""
  cmd="alog -ot cfg > $snapdir/alog.cfg 2>&1"
  run_cmd

  lsdev -C -F name | \
  while read name
  do
	string="lsattr -El $name"
	cmd="lsattr -El $name >> $snapfile 2>&1"
	run_cmd
  done

  # Capture system console device
  if [ -x /usr/sbin/lscons ]
  then
	string="lscons -a"
	cmd="/usr/sbin/lscons -a >> $snapfile 2>&1"
	run_cmd
  fi
  # End of Capturing system console device

  if [ -x /usr/sbin/lsmcode ]
  then
      string="lsmcode -A"
      cmd="/usr/sbin/lsmcode -A >> $snapfile 2>&1"
      run_cmd
  fi

  if [ -x /usr/sbin/lscfg ]
  then
  	string="lscfg -pv"	# Added p for Platform Specific info 
  	cmd="lscfg -pv >> $snapfile 2>&1"
  	run_cmd
  fi

  if [ -x /usr/sbin/lsdclient ]
  then
  	string="lsdclient -l"
  	cmd="lsdclient -l >> $snapfile 2>&1"
  	run_cmd
  fi

  if [ -x /usr/sbin/lsspot ]
  then
  	string="lsspot -l"
  	cmd="lsspot -l >> $snapfile 2>&1"
  	run_cmd
  fi

  if [ -x /usr/bin/sysdumpdev ]
  then
        string="sysdumpdev -L -v"
        cmd="sysdumpdev -L -v >> $snapfile 2>&1"
        run_cmd
  fi

  if [ -f /var/perf/tmp/.SM ]
  then
  	string=""
  	cmd="cp -p /var/perf/tmp/.SM $snapdir > /dev/null 2>&1"
  	run_cmd
  fi

  cwd=`pwd`
  cd /etc/objrepos
  filelist=`ls Cu* ATM_PVC 2>/dev/null`
  for files in $filelist
  do
	string=""
  	cmd="odmget $files > $snapdir/$files.add 2>/dev/null"
	run_cmd
  done
  cd $cwd


  string=" "
  #Defect 1029994: Please refer to Note1 in the run_cmd section on how to add an Informational message
  cmd="echo \\\n\"********** STO and AIX Dump Settings  **********\"\\\n >> $setfile 2>&1"
  run_cmd

  string=" "
  #Defect 1029994: Please refer to Note1 in the run_cmd section on how to add an Informational message 
  cmd="echo \\\n\"********** STO Settings  ***********\"\\\n >> $setfile 2>&1"
  run_cmd

  if [ -x /usr/lpp/diagnostics/bin/uspchrp ] && [ chrp = `/usr/sbin/bootinfo -p` ]
  then

    string=""
    #Defect 1029994: Please refer to Note1 in the run_cmd section on how to add an Informational message
    cmd="echo \"* STO Enabled *\"\\\n >> $setfile 2>&1"
    run_cmd

    string=""
    cmd="/usr/lpp/diagnostics/bin/uspchrp -q sp-sen >> $setfile 2>&1"
    run_cmd

    string=""
    #Defect 1029994: Please refer to Note1 in the run_cmd section on how to add an Informational message
    cmd="echo \"* STO Interval *\"\\\n >> $setfile 2>&1"
    run_cmd

    string=""
    cmd="/usr/lpp/diagnostics/bin/uspchrp -q sp-sti >> $setfile 2>&1"
    run_cmd

    string=""
    #Defect 1029994: Please refer to Note1 in the run_cmd section on how to add an Informational message
    cmd="echo \"* STO Delay *\"\\\n >> $setfile 2>&1"
    run_cmd

    string=""
    cmd="/usr/lpp/diagnostics/bin/uspchrp -q sp-sdel >> $setfile 2>&1"
    run_cmd

  fi

  string=""
  #Defect 1029994: Please refer to Note1 in the run_cmd section on how to add an Informational message
  cmd="echo \\\n\"**********  AIX Dump Device Settings  (sysdumpdev -l) **********\"\\\n >> $setfile 2>&1"
  run_cmd

  string=""
  cmd="sysdumpdev -l >> $setfile 2>&1"
  run_cmd

  string=""
  #Defect 1029994: Please refer to Note1 in the run_cmd section on how to add an Informational message
  cmd="echo \\\n\"**********  AIX Estimated Dump Size (sysdumpdev -e) **********\"\\\n >> $setfile 2>&1"
  run_cmd

  string=""
  cmd="sysdumpdev -e >> $setfile 2>&1"
  run_cmd

  if [ -x /etc/methods/cfgbus ]
  then
        string="Running cfgbus on MCA machine."
        cmd="/etc/methods/cfgbus -l bus0 -d >> $snapfile 2>&1"
        run_cmd

        string=""
        cmd="cp -p BUS* $snapdir >>/dev/null 2>&1"
        run_cmd
  fi

  if [ -x /usr/sbin/emgr ]
  then	# Gather efix info.
	string=""
	cmd="/usr/sbin/emgr -lv3 > $snapdir/emgr.snap 2>&1"
	run_cmd
  fi

  if [ -x /usr/sbin/ctctrl ]
  then
        string=""
        cmd="/usr/sbin/ctctrl -q > $snapdir/ctctrl.snap 2>&1"
        run_cmd
  fi

  if [ -x /usr/sbin/errctrl ]
  then
        string=""
        cmd="/usr/sbin/errctrl -q > $snapdir/errctrl.snap 2>&1"
        run_cmd
  fi

  if [ -x /usr/sbin/dumpctrl ]
  then
        string=""
        cmd="/usr/sbin/dumpctrl -qc > $snapdir/dumpctrl.snap 2>&1"
        run_cmd
  fi

  if [ -x /usr/sbin/ikedb ]
  then
        string="ikedb -g"
  	cmd="/usr/sbin/ikedb -g > $snapdir/ikedb.xml 2>&1"
  	run_cmd

        string="ikedb -o"
  	cmd="/usr/sbin/ikedb -o > $snapdir/ikedb.dtd 2>&1"
  	run_cmd
  fi

  if [ -x /usr/sbin/ike ]
  then
	lssrc -s tmd | grep "active" >/dev/null 2>&1
	if [ "$?" = 0 ]
	then
        	string="ike cmd=list"
  		cmd="/usr/sbin/ike cmd=list > $snapdir/ike.list 2>&1"
  		run_cmd
	fi

        string="ike cmd=list db"
  	cmd="/usr/sbin/ike cmd=list db verbose > $snapdir/ike.db 2>&1"
  	run_cmd
  fi

  if [ -x /usr/sbin/lsfilt ]
  then
        string="lsfilt -a"
  	cmd="/usr/sbin/lsfilt -a > $snapdir/lsfilt.active 2>&1"
  	run_cmd

        string="lsfilt"
  	cmd="/usr/sbin/lsfilt > $snapdir/lsfilt 2>&1"
  	run_cmd
  fi

  if [ -x /usr/sbin/ipsecstat ]
  then
        string="ipsecstat"
  	cmd="/usr/sbin/ipsecstat > $snapdir/ipsecstat 2>&1"
  	run_cmd
  fi

  if [ -x /usr/sbin/lstun ]
  then
        string="lstun -a"
  	cmd="/usr/sbin/lstun -a > $snapdir/lstun.active 2>&1"
  	run_cmd

        string="lstun"
  	cmd="/usr/sbin/lstun > $snapdir/lstun 2>&1"
  	run_cmd
  fi

  if [ -x /usr/lib/methods/loadkclic ]
  then
        string="loadkclic"
  	cmd="/usr/lib/methods/loadkclic -q > $snapdir/loadkclic 2>&1"
  	run_cmd
  fi

  # diagela_exec -a :  Determine if a HMC attached
  # 0 if HMC is not attached
  # 1 if HMC is attached
  # -1 can not determine environment
  if [ -x /usr/lpp/diagnostics/bin/diagela_exec ]
  then
        rc_diag=`/usr/lpp/diagnostics/bin/diagela_exec -a>/dev/null 2>/dev/null;echo $?`
        string="Return code of /usr/lpp/diagnostics/bin/diagela_exec -a"
        cmd="echo $rc_diag >> $snapfile 2>&1"
        run_cmd
  fi

  # nim logs for viosupgrade
  if [ -x /var/adm/ras ]
  then
        string=""
        cmd="cp -p /var/adm/ras/*nim* $nimdir >/dev/null 2>&1"
        run_cmd

	# if capturing nimsh.log, we need to make sure passwords are not shown
	sed '/hmcauth.*/s/-p [^ ]* /-p ****** /g' $nimdir/nimsh.log > $nimdir/nimsh.log.tmp
	mv $nimdir/nimsh.log.tmp $nimdir/nimsh.log

        string=""
        cmd="alog -f $nimdir/nimlog -o > $nimdir/nimlog.out 2>/dev/null; rm $nimdir/nimlog 2>/dev/null"
        run_cmd
  fi

  if [ -x /var/adm/ras/ioslogs ]
  then
        string=""
        cmd="cp -p /var/adm/ras/ioslogs/* $nimdir >/dev/null 2>&1"
        run_cmd
  fi

  [ "$passno" != 1 ] && echo " done."

  if [ "$dopred" = "y" ] 
  then
	[ "$passno" != 1 ] && echo "Including Pd* ODM files in general information...\c"
	cwd=`pwd`
	cd /etc/objrepos
	filelist=`ls Pd*`
	for files in $filelist
	do
		string=""
 		cmd="odmget $files > $snapdir/$files.add 2>/dev/null"
		run_cmd
	done
  	cd $cwd
	
	[ "$passno" != 1 ] && echo " done."
  fi

  if [ "$dosec" = "y" ]
  then
	[ "$passno" != 1 ] && echo "Including security files in general information\c"
	string=""
	cmd="cp -p /etc/passwd $snapdir/passwd.etc >/dev/null 2>&1"
	run_cmd

	string=""
	cmd="cp -p /etc/group $snapdir/group.etc >/dev/null 2>&1"
	run_cmd

        string=""
        cmd="cp -p /tmp/s.slapd $snapdir/s.slapd >/dev/null 2>&1"
        run_cmd

        string=""
        cmd="cp -p /tmp/slapd.errors $snapdir/slapd.errors >/dev/null 2>&1"
        run_cmd  
 
        string=""
        cmd="cp -p /etc/slapd32.conf $snapdir/slapd32.conf.etc >/dev/null 2>&1"
        run_cmd  

	# Capture Pam configuration
	string=""
	cmd="cp -p /etc/pam.conf  $snapdir/pam.conf >/dev/null 2>&1"
	run_cmd
	# End of Capturing Pam configuration

	# Capture keberos configuration
        if [ -e /etc/krb5 ]
        then
		filelist=`find /etc/krb5 ! \( -type d -o -type p -o -type s \) -print`
		for file in $filelist
		do
			string=""
			cmd="cp -p $file $snapdir >/dev/null 2>&1"
			run_cmd
		done
        fi
	# End of Capturing keberos configuration

        string=""
        cmd="cp -p /usr/lib/security/methods.cfg $snapdir/security.methods.cfg >/dev/null 2>&1"
        run_cmd

	string=""
	cmd="cp -p /etc/ssh/ssh_config $snapdir/ssh_config >/dev/null 2>&1"
	run_cmd

	string=""
	cmd="cp -p /etc/ssh/sshd_config $snapdir/sshd_config >/dev/null 2>&1"
	run_cmd

	filelist=`(cd /etc/security; find . ! \( -type d -o -type p -o -type s \) -print )`
	for file in $filelist
	do
		if [ ! -d $snapdir/$(dirname $file) ]
		then
			string=""
			cmd="mkdir -p $snapdir/$(dirname $file) >> /dev/null 2>&1"
			run_cmd
		fi

                # Capturing the /etc/security/passwd is the security violation(defect :807389).
                # So the below condition is used to skip the code that capture the /etc/security/passwd

                if [ $file != "./passwd" ]
                then
                        string=""
                        cmd="cp -p /etc/security/$file $snapdir/$file >/dev/null 2>&1"
                        run_cmd
                fi
	done

        filelist=`find /etc/ipsec ! \( -type d -o -type p -o -type s \) -print` 
	for file in $filelist
	do
		string=""
		cmd="cp -p $file $snapdir >/dev/null 2>&1"
		run_cmd
	done

        filelist=`find /var/security ! \( -type d -o -type p -o -type s \) -print` 
	for file in $filelist
	do
		string=""
		cmd="cp -p $file $snapdir >/dev/null 2>&1"
		run_cmd
	done
	[ "$passno" != 1 ] && echo " done."
  fi

  [ "$passno" = 1 ] && echo " done."

} # End of state_func1

# Function state_func2
state_func2 () {
#            
# 

  comp=tcpip
  snapfile=$destdir/$comp/$comp.snap
  snapdir=$destdir/$comp

  if [ "$passno" = 1 ]
  then
  	echo "Checking space requirement for $comp information\c"
  else
  	echo "Gathering $comp system information\c"
  fi

  string="creation date"
  cmd="date > $snapfile 2>&1"
  run_cmd

  string="Note: If you want the /var/adm/ras/trcfile, snap -g will get it"
  cmd=""
  run_cmd

  string="lssrc -a"
  cmd="lssrc -a >> $snapfile 2>&1"
  run_cmd

  string="netstat -m"
  cmd="netstat -m >> $snapfile 2>&1"
  run_cmd

  string="netstat -in"
  cmd="netstat -in >> $snapfile 2>&1"
  run_cmd
  
  string="netstat -v"
  cmd="netstat -v >> $snapfile 2>&1"
  run_cmd

  string="netstat -s"
  cmd="netstat -s >> $snapfile 2>&1"
  run_cmd

  string="netstat -an"
  cmd="netstat -an >> $snapfile 2>&1"
  run_cmd

  string="netstat -sr"
  cmd="netstat -sr >> $snapfile 2>&1"
  run_cmd

  string="netstat -nr"
  cmd="netstat -nr >> $snapfile 2>&1"
  run_cmd

  string="netstat -ano"
  cmd="netstat -ano >> $snapfile 2>&1"
  run_cmd

  string="ifconfig -a"
  cmd="ifconfig -a >> $snapfile 2>&1"
  run_cmd

  string="no -Fa"
  cmd="no -Fa >> $snapfile 2>&1"
  run_cmd

  string="arp -a"
  cmd="arp -a >> $snapfile 2>&1"
  run_cmd

  string="arp -t atm -a"
  cmd="arp -t atm -a >> $snapfile 2>&1"
  run_cmd

  string="uname -xM"
  cmd="uname -xM >> $snapfile 2>&1"
  run_cmd 

  string="Interface Configs"
  cmd="interconfig >> $snapfile 2>&1"
  run_cmd

  string="Name Server "
  cmd="lsnamsv -C >> $snapfile 2>&1"
  run_cmd

  # ATM stats
  if [ -x /usr/sbin/lecstat ]
  then
      string="ATM LAN Emulation (LANE) Client information"
      cmd="/usr/sbin/lecstat -a >> $snapfile 2>&1"
      run_cmd
  fi

  if [ -x /usr/sbin/mpcstat ]
  then
      string="Multi-Protocol Over ATM (MPOA) Client Information"
      cmd="/usr/sbin/mpcstat -a >> $snapfile 2>&1"
      run_cmd
  fi

  if [ -x /usr/sbin/atmvcstat ]
  then
      lsdev -Cc adapter -F name | grep atm | { 
	  while read device; 
	    do
	    string="ATM virtual circuit information for $device"
	    cmd="atmvcstat $device >> $snapfile 2>&1"
	    run_cmd
	  done 
      }
  fi

  # Check if we are nameserver

  [ -r /etc/resolv.conf ] && numbytes=`ls -al /etc/resolv.conf | awk '{ print $5 }'` || numbytes=1

  if [ "$numbytes" = "0" ] 
  then

	# See if named running

	ps -ef | fgrep named | fgrep -v fgrep >/dev/null 2>&1
	if [ "$?" = "0" ]
	then
		# See if -b flag specified with named for alternate boot file
		# otherwise assume /etc/named.boot
		bootfile=`ps -ef | fgrep named |fgrep -v fgrep | awk '
			{ 
     				for (i = 0; i <= NF; ++i) 
 					if ($i == "-b") {            
     						print $(i + 1);         
						exit 15;
					}
			}'`
	else
		# /etc/resolv.conf = 0 bytes, named not running, assume 
		# /etc/named.boot as bootfile
		bootfile=/etc/named.boot
	fi
	
	# named is running but no -b flag so assume /etc/named.boot
	[ ! -s "$bootfile" ] && bootfile=/etc/named.boot

	# copy named database files to snap directory

	string=""
	cmd="cp -p $bootfile `awk '
		$1 == "primary" || $1 == "cache" || $1 == "secondary" {
		print $NF
		}' $bootfile` $snapdir >/dev/null 2>&1"
        if [ "$?" != "0" ]
        then
                echo "\nAssumed named is running without -b flag so assumed /etc/named.boot is the boot file for the nameserver.  Could be that nameserver is not configured correctly.\n"
        fi
	run_cmd
  fi

  for dev in "$( lsdev -Cc adapter -S A -F name,ddins | grep rrhbadd | sed -e 's%,.*%%' )"
  do
    string="hbastat -d -qset all $dev"
    cmd="hbastat -d -qset all $dev >> $snapfile 2>&1"
    run_cmd
  done

  string=""
  cmd="cp -p /etc/sendmail.cf $snapdir >/dev/null 2>&1"
  run_cmd
  string=""
  cmd="cp -p /etc/aliases $snapdir >/dev/null 2>&1"
  run_cmd
  string=""
  cmd="cp -p /etc/binld.cnf $snapdir >/dev/null 2>&1"
  run_cmd
  string=""
  cmd="cp -p /etc/bootptab $snapdir >/dev/null 2>&1"
  run_cmd
  string=""
  cmd="cp -p /etc/clsnmp.conf $snapdir >/dev/null 2>&1"
  run_cmd
  string=""
  cmd="cp -p /etc/dhcprd.cnf $snapdir >/dev/null 2>&1"
  run_cmd
  string=""
  cmd="cp -p /etc/dhcpsd.cnf $snapdir >/dev/null 2>&1"
  run_cmd
  string=""
  cmd="cp -p /etc/dhcpcd.ini $snapdir >/dev/null 2>&1"
  run_cmd
  string=""
  cmd="cp -p /etc/dlpi.conf $snapdir >/dev/null 2>&1"
  run_cmd
  string=""
  cmd="cp -p /etc/gated.conf $snapdir >/dev/null 2>&1"
  run_cmd
  string=""
  cmd="cp -p /etc/hostmibd.conf $snapdir >/dev/null 2>&1"
  run_cmd
  string=""
  cmd="cp -p /etc/hosts $snapdir >/dev/null 2>&1"
  run_cmd
  string=""
  cmd="cp -p /etc/hosts.equiv $snapdir >/dev/null 2>&1"
  run_cmd
  string=""
  cmd="cp -p /etc/inetd.conf $snapdir >/dev/null 2>&1"
  run_cmd
  string=""
  cmd="cp -p /etc/mib.defs $snapdir >/dev/null 2>&1"
  run_cmd
  string=""
  cmd="cp -p /etc/mrouted.conf $snapdir >/dev/null 2>&1"
  run_cmd
  string=""
  cmd="cp -p /etc/policyd.conf $snapdir >/dev/null 2>&1"
  run_cmd
  string=""
  cmd="cp -p /etc/protocols $snapdir >/dev/null 2>&1"
  run_cmd
  string=""
  cmd="cp -p /etc/pse.conf $snapdir >/dev/null 2>&1"
  run_cmd
  string=""
  cmd="cp -p /etc/pse_tune.conf $snapdir >/dev/null 2>&1"
  run_cmd
  string=""
  cmd="cp -p /etc/pxed.cnf $snapdir >/dev/null 2>&1"
  run_cmd
  string=""
  cmd="cp -p /etc/rc.bsdnet $snapdir >/dev/null 2>&1"
  run_cmd
  string=""
  cmd="cp -p /etc/rc.net $snapdir >/dev/null 2>&1"
  run_cmd
  string=""
  cmd="cp -p /etc/rc.net.serial $snapdir >/dev/null 2>&1"
  run_cmd
  string=""
  cmd="cp -p /etc/rc.qos $snapdir >/dev/null 2>&1"
  run_cmd
  string=""
  cmd="cp -p /etc/rc.tcpip $snapdir >/dev/null 2>&1"
  run_cmd
  string=""
  cmd="cp -p /etc/resolv.conf $snapdir >/dev/null 2>&1"
  run_cmd
  string=""
  cmd="cp -p /etc/rsvpd.conf $snapdir >/dev/null 2>&1"
  run_cmd
  string=""
  cmd="cp -p /etc/services $snapdir >/dev/null 2>&1"
  run_cmd
  string=""
  cmd="cp -p /etc/slip.hosts $snapdir >/dev/null 2>&1"
  run_cmd
  string=""
  cmd="cp -p /etc/slp.conf $snapdir >/dev/null 2>&1"
  run_cmd
  string=""
  cmd="cp -p /etc/snmpd.conf $snapdir >/dev/null 2>&1"
  run_cmd
  string=""
  cmd="cp -p /etc/snmpd.peers $snapdir >/dev/null 2>&1"
  run_cmd
  string=""
  cmd="cp -p /etc/snmpdv3.conf $snapdir >/dev/null 2>&1"
  run_cmd
  string=""
  cmd="cp -p /etc/syslog.conf $snapdir >/dev/null 2>&1"
  run_cmd
  string=""
  cmd="cp -p /etc/telnet.conf $snapdir >/dev/null 2>&1"
  run_cmd
  string=""
  cmd="cp -p /etc/xtiso.conf $snapdir >/dev/null 2>&1"
  run_cmd

  string=""
  cmd="cp -p /tmp/rc.net.out $snapdir >/dev/null 2>&1"
  run_cmd 

  echo " done."


} # End of state_func2

# Function state_func4
state_func4 () {
#            
# 
  comp=kernel
  snapfile=$destdir/$comp/$comp.snap
  snapdir=$destdir/$comp

  if [ "$passno" = 1 ]
  then
  	echo "Checking space requirement for $comp information\c"
  else
  	echo "Gathering $comp system information\c"
  fi


  string="creation date"
  cmd="date >> $snapfile 2>&1"
  run_cmd

  string="Note: If you want the /var/adm/ras/trcfile, snap -g will get it"
  cmd=""
  run_cmd

  string="bootinfo -r"
  cmd="bootinfo -r >> $snapfile 2>&1"
  run_cmd

  string="bootinfo -K"
  cmd="bootinfo -K >> $snapfile 2>&1"
  run_cmd 
 
  string="vmstat"
  cmd="vmstat >> $snapfile 2>&1"
  run_cmd

  string="vmstat -s"
  cmd="vmstat -s >> $snapfile 2>&1"
  run_cmd

  vmo=/usr/sbin/vmo
  if [ -x $vmo ]
  then	# vmo
  	string="vmo -FL"
  	cmd="$vmo -FL >> $snapfile 2>&1"
  	run_cmd
  fi

  ioo=/usr/sbin/ioo
  if [ -x $ioo ]
  then	# ioo
  	string="ioo -FL"
  	cmd="$ioo -FL >> $snapfile 2>&1"
  	run_cmd 
  fi

  schedo=/usr/sbin/schedo
  if [ -x $schedo ]
  then	# schedo
  	string="schedo -FL"
  	cmd="$schedo -FL >> $snapfile 2>&1"
  	run_cmd 
  fi

  string="vmstat -v"
  cmd="vmstat -v >> $snapfile 2>&1"
  run_cmd

  string="env"
  cmd="env >> $snapfile 2>&1"
  run_cmd

  string="lssrc -a"
  cmd="lssrc -a >> $snapfile 2>&1"
  run_cmd

  string="ps -ef"
  cmd="ps -ef >> $snapfile 2>&1"
  run_cmd

  string="ps -e@f"
  cmd="ps -e@f >> $snapfile 2>&1"
  run_cmd

  string="ps -leaf"
  cmd="ps -leaf >> $snapfile 2>&1"
  run_cmd

  string="sum on /etc/methods/*"
  cmd="sum /etc/methods/* >> $snapfile 2>&1"
  run_cmd

  string="sum on /etc/drivers/*"
  cmd="sum /etc/drivers/* >> $snapfile 2>&1"
  run_cmd

  echo " done."

} # End of state_func4

# Function state_func5
state_func5 () {
#            
# 
  comp=printer
  snapfile=$destdir/$comp/$comp.snap
  snapdir=$destdir/$comp

  if [ "$passno" = 1 ]
  then
  	echo "Checking space requirement for $comp information\c"
  else
  	echo "Gathering $comp system information\c"
  fi


  string="creation date"
  cmd="date >> $snapfile 2>&1"
  run_cmd

  string="enq -AL"
  cmd="enq -AL >> $snapfile 2>&1"
  run_cmd

  string="lsdev -Ccprinter"
  cmd="lsdev -Ccprinter >> $snapfile 2>&1"
  run_cmd

  for j in `lsdev -Cc printer -F name`
  do
    string="lsattr -El $j"
    cmd="lsattr -El $j >> $snapfile 2>&1"
    run_cmd
  done

  string=""
  cmd="cp -p /etc/qconfig $snapdir 2>&1"
  run_cmd

  echo " done."


} # End of state_func5

# is iscsi disk dump device
is_this_iscsi_dump_device() {
    isiscsidev=`odmget -q "name=$1 and attribute=target_name" CuAt | grep -wc target_name `
    
}
# Function check_compress_header
check_compress_header () {
    compress_header=""

    is_this_iscsi_dump_device `basename $1`
    if [ "$isiscsidev" -ne 0 ] 
    then
		off=`lquerypv -h $1 0x200 10 | awk '{print $4$5}'` 
		bsize=0x200
		xoffset=`echo 0x$off $bsize | awk '{ printf("%08X", $1*$2)}'`
		xsize=`printf  "%08X" 516`
		compress_header=`lquerypv -h $1 $xoffset $xsize | awk ' 
			    {
			    if ($1 == offset && $2 == "64626444") {print "3";}
			    }' offset=$xoffset `  > /dev/null 2>&1	
    else
		# Get the VG name wher dump lv belongs to
		myvgname=`lslv -L \`basename $1\` | grep "VOLUME GROUP:" | awk -F: '{print $NF}' `
		# check if, Disk Block size is 4k
		lsvg $myvgname | grep "DISK BLOCK SIZE:" | tr -d " "| grep "DISKBLOCKSIZE:4096" >/dev/null 2>&1
		if [[ $? = 0 ]]
		then
			# if, disk block size = 4k
			compress_header=`head -c4100 $1 | od -x | awk '
			{
				if ($1 == "0000000" && $2 == "1f9d") {print "1";}
				if ($1 == "0010000" && $2 == "1f9d") {print "2";}
				if ($1 == "0000000" && $2 == "6462" && $3 == "6444") {print "3";}
				if ($1 == "0010000" && $2 == "6462" && $3 == "6444") {print "4";}
			}'`  > /dev/null 2>&1
		else
			# if, disk block size = 512
			compress_header=`head -c516 $1 | od -x | awk '
			{
				 if ($1 == "0000000" && $2 == "1f9d") {print "1";}
				 if ($1 == "0001000" && $2 == "1f9d") {print "2";}
				 if ($1 == "0000000" && $2 == "6462" && $3 == "6444") {print "3";}
				 if ($1 == "0001000" && $2 == "6462" && $3 == "6444") {print "4";}
			}'`  > /dev/null 2>&1
		fi
    fi
} # End of  check_compress_header

#function is_this_tape_device
is_this_tape_device() {
#
	istapdev=`odmget -q "name = $1" CuDv  |grep PdDvLn |grep tape |wc -l |awk '{print $1}'`

} # End of is_this_tape_device

#function is_this_cdrom_device - set the iscdrdev variable.
is_this_cdrom_device() {
#
	iscdrdev=`odmget -q "name = $1" CuDv  |grep PdDvLn |grep cdrom |wc -l`

} # End of is_this_cdrom_device

# Get dump info using sysdumpdev -L and awk.
# This sets 
#   $dumpdev - device containing most recent dump.
#   $basdumpdev - basename $dumpdev
#   $dumpsize - dump size in bytes. Doesn't include a 512 byte header.
#   $uncompsize - Uncompressed dump size, 0 if not compressed.
#   $istapdev - non-zero if dump from tape.
#   $dumprc - dump return code.
#   $cpyfn - dump copy file name.
get_dump_info() {
	sysdumpdev -L 2>/dev/null | awk '
	  BEGIN {
	    siz=0
	    uncsiz=0
	    rc=0
	    fn=""
	  }
	  $0 ~ /^Device name/ {name=$NF}
	  $0 ~ /^Size/ {siz=$2}
	  $0 ~ /^Uncompressed / {uncsiz=$3}
	  $0 ~ /^Dump status/ {rc=$NF}
	  $0 ~ /^Dump copy filename/ {fn=$NF}
	  END {printf("%s %s %s %s %s\n", name,siz,uncsiz,rc,fn)}' |\
	  read dumpdev dumpsize uncdumpsize dumprc cpyfn
	[[ -z "$dumpdev" ]] && return 2 # No previous dump.
	basdumpdev=`basename $dumpdev`
	is_this_tape_device $basdumpdev
	is_this_cdrom_device $basdumpdev
	return 0
}

# Get the current dump devices.
# Output:  two items, primary and secondary devs, to stdout.
getcrntdumpdev() {
	sysdumpdev -l | awk '
	  $1 == "primary" {printf("%s ",$NF)}
	  $1 == "secondary" {print $NF; exit 0}'
	return $?
}

# Get the dump from paging space.
# $tdumpf contains sysdumpdev -L output.
# $invalid is set to 1 if the dump copy on boot failed.
# $dumpsize_included is set to 1 if a link is made.
# $noadump is set to 1 if the dump is compressed.
dump_from_ps() {
	# The dump device is paging space.
	# The copy filename is in $cpyfn.
	if [ -n "$cpyfn" ]
	then
	   # Check for compress magic header
	   check_compress_header $cpyfn

	   if [ "$compress_header" == 1 -o "$compress_header" == 2 ]
	     then
		compressed_dump_file="$snapdir/dump.Z"
	     else if [ "$compress_header" == 3 -o "$compress_header" == 4 ]
	     then
		compressed_dump_file="$snapdir/dump.BZ"
	     fi
	   fi

	   # The dump was copied to a file successfully.
	   if [ "$bad_unix" != 1 -a "$passno" = 2 ]
	   then
		   string=""
		   if [ -n "$compress_header" ]
		   then
			cmd="ln -fs $cpyfn $compressed_dump_file >> $snapfile 2>&1"
			run_cmd
			noadump=1	# adump won't work on a compressed dump.
		   else
			cmd="ln -fs $cpyfn $snapdir/dump >> $snapfile 2>&1"
			run_cmd
		   fi
	   fi
	   dumpdev=`echo $cpyfn`
	   # Indicate space accounted for.
	   dumpsize_included=1

	else
	   # The attempt to copy the dump on boot failed.
	   invalid=1	
	   string="Status of Dump Copy"
	   cmd="echo 'A dump was taken to $dumpdev, but an attempt to copy the dump\nto a file on boot failed.' >> $snapfile 2>&1" 
	   run_cmd

	   # Allow user to copy dump from external media
	   if [ "$passno" = 1 ]
	   then
		# Get user input and update snap sizing 
		echo "\n\n\
The previous dump to paging space was not copied to disk at reboot.\n\
You were given the opportunity to copy the dump to external media.\n\
Would you like to restore the dump? (y/n)  \c"

		#dodmpcpy is one char, lowercase
		read dodmpcpy
		if [ "$dodmpcpy" = y ]
		then
			# Get device name
			valid_idev
			echo "\nPlease insert the media containing the dump into $tapedev and press Enter\c"
			read

		else
			# User chose not to copy dump
			echo "\nWARNING: No dump image will be collected.\n"
		fi
		# Get the size from the sysdumpdev -L info.
		dumpsize_included=1
		total_bytes=`expr $total_bytes + $dumpsize`
	   else 
		# pass 2 - Extract dump file
		if [ "$dodmpcpy" = y ]
		then
			echo "\nExtracting the dump from external media."
			cd $snapdir
			dump_file=`pax -vf $tapedev | grep dump |  awk '{printf $NF}'`
			string="Extract dump from media"
			cmd="pax -xpax -rf $tapedev $dump_file >> $snapfile 2>&1"
			run_cmd

			if [ -f "$snapdir/$dump_file" ]
			then
	   			check_compress_header $dump_file
				if [ "$compress_header" == 1 -o "$compress_header" == 2 ]
				then
				    compressed_dump_file="$snapdir/dump.Z"
				else if [ "$compress_header" == 3 -o "$compress_header" == 4 ]
				  then
				    compressed_dump_file="$snapdir/dump.BZ"
				  fi
				fi

		   		if [ -n "$compress_header" ]
		   		then
					mv $snapdir/$dump_file $compressed_dump_file 
					dump_file=$compressed_dump_file
					noadump=1
				else # not compressed.
				    # Check whether unix and dump match,
				    # couldn't be done in pass 1.
				    /usr/lib/ras/check_unix $snapdir/$dump_file
				    if [ "$?" -eq 1 ]
				    then
					string="Status of check_unix"
					cmd="echo '\nWARNING - unix does not match dump_file' >> $snapfile 2>&1"
					run_cmd
					echo "\nWARNING: The /unix file does not match the dump extracted
from $tapedev.  The /unix must be the same unix, or linked
to the same unix, that was running when the dump occurred.
Possible Causes:
1) The /unix file does not exist.
2) The dump that was taken is a partial dump.
3) The /unix file on your system was replaced,
   and the bosboot command was not run.  If this is the
   case, then run the bosboot command and reboot your
   system.
4) The media did not contain the latest dump or the
   wrong media was used.\n"
				    fi
				fi # end of if dump compressed
			else
				# dump_file does not exist
				echo "\nWARNING - unable to restore dump from $tapedev" | tee -a $snapfile
			fi

			# If input device=output device,
			# prompt user to remove dump
			# media and insert output media
			if [ "$dodev" = y -a "$tapedev" = "$devtype" ]
			then
				echo "\nPlease remove dump media and replace with snap output media.\n"
				echo "\nPress enter to continue\c"
				read
			fi
							
		fi 	
	   fi	# Pass2 
		
	fi	# End of external dump copy code
	return 0
}

# The dump is on a dedicated dump device.
dump_from_local() {
	# initialize compressed_dump_file
    	compressed_dump_file="$snapdir/dump.Z"
	# Check for compress magic header
	check_compress_header $dumpdev
        if [ "$compress_header" == 1 -o "$compress_header" == 2 ]
        then
                compressed_dump_file="$snapdir/dump.Z"
        else if [ "$compress_header" == 3 -o "$compress_header" == 4 ]
          then
             compressed_dump_file="$snapdir/dump.BZ"
          fi
	fi

	if [ "$bad_unix" != 1 ]
	then
		string=""
		# We use pass 1 to get dump size.
		dumpsize_included=1
		if [ "$compress_header" = '1' -o "$compress_header" = '3' ]
		then
			# compress hdr at offset 0.
			blks=`expr "(" $dumpsize + 32767 ")" / 32768`
			cmd="/usr/lib/ras/dumpread -d $dumpdev | dd bs=32k count=$blks  > $compressed_dump_file"
			noadump=1
		else if [ "$compress_header" = '2' -o "$compress_header" = '4' ]
		     then
			# compress hdr at offset 512.
			# no need to make changes here as dumpread writes blocks in size
			# of 512 only so this is fine.
			# dumpread takes care of 4k and 512 disk block size internally.
				blks=`expr "(" $dumpsize + 511 ")" / 512`
				cmd="/usr/lib/ras/dumpread -d $dumpdev | dd ibs=512 obs=64k count=$blks > $compressed_dump_file"
				noadump=1
		     else
			# Not compressed.
			    if [ $passno = 1 -a $dumpsize -gt 2147483648 ]
			    then	# Don't try the compress for such a large dump.
				    echo "\n\
warning:  This is a very large dump, more than 2 gb.\n\
We won't attempt to check the space requirement which can't be determined\n\
without doing the compression."
					return 0
			    else	# pass 2 or smaller than 2 gb.
					blks=`expr "(" $dumpsize + 32767 ")" / 32768`
					cmd="/usr/lib/ras/dumpread -d $dumpdev | dd bs=32k count=$blks | compress > $compressed_dump_file"
			    fi
		 
		     fi
		fi
		run_cmd
	fi
	return 0
}

# The dump is on a cdrom
dump_from_cdrom() {
	# Get the real device for performance.
	realdev=`dirname $dumpdev`"/r"`basename $dumpdev`

	# Check for compress magic header
	check_compress_header $dumpdev
	if [ "$bad_unix" != 1 ]
	then
		string=""
		# We use pass 1 to get dump size.
		dumpsize_included=1
		compress_file=
		if [ "$compress_header" = '1' ]
		then
		    compress_file="dump.Z"
		 else if [ "$compress_header" = '3' ]
		 then
		    compress_file="dump.BZ"
		 fi
		fi

		if [ "$compress_file" != "" ]
		then
			# compress hdr at offset 0.
			blks=`expr "(" $dumpsize + 65535 ")" / 65536`
			cmd="dd bs=64k count=$blks if=$realdev > $snapdir/$compress_file"
			noadump=1
		else	# Not compressed.
			if [ $passno = 1 -a $dumpsize -gt 1073741824 ]
			then	# Don't try the compress for such a large dump.
				    echo "\n\
warning:  This is a large dump, more than 1 gb.\n\
We won't attempt to check the space requirement which can't be determined\n\
without doing the compression."
				return 0
			else	# pass 2 or smaller than 1 gb.
			    blks=`expr "(" $dumpsize + 65535 ")" / 65536`
			    cmd="dd bs=64k count=$blks if=$realdev | compress > $snapdir/dump.Z"	
			fi
		fi
		run_cmd
		# Snip off excess bytes at end if compressed.
		if [ $passno = 2 ]
		then
		    if [ "$compress_header" = '1' -o "$compress_header" = '3' ]
		    then	
			/usr/lib/ras/dumptrunc $snapdir/$compress_file $dumpsize
		    fi
		fi
	fi
	return 0
}

# Get the dump from tape.
# Note that we can't run check_unix on a dump from tape, because it's
# either compressed, or we compress it when we copy it.
# $noadump is set to 1, won't do adump on a tape.
# $dumpsize_included is set to 1, we figure out the size here.
dump_from_tape() {
	noadump=1
	dumpsize_included=1

	# Check for a huge, uncompressed dump.
	if [ $passno = 1 -a $dumpsize -gt 2147483648 -a $uncdumpsize = 0 ]
	then	# Don't try the compress for such a large dump.
		echo "\n\
warning:  This is a very large dump, more than 2 gb.\n\
We won't attempt to check the space requirement which can't be determined\n\
without doing the compression."
		return 0
	fi

	if [ $uncdumpsize -ne 0 ]
	then	# The dump is compressed.
		if [ $passno = 1 ]
		then	# We know how big it is, won't compress on pass 2.
			total_bytes=`expr $total_bytes + $dumpsize`
			return 0
		fi
	fi # end of "if compressed dump"

	# See if the tape is currently a dump device.
	getcrntdumpdev | read prim sec
	sw=
	todev=/dev/hd6
	if [ "$dumpdev" = "$prim" ] 
	then	sw='-p'
		# See if the secondary is already what we want.
		[ "$sec" = $todev ] && todev=/dev/sysdumpnull
	else if [ "$dumpdev" = "$sec" ] 
	     then
		sw='-s'
		# See if the primary is already what we want.
		[ "$prim" = $todev ] && todev=/dev/sysdumpnull
	    fi
	fi
	if [[ -n "$sw" ]]
	then
		sysdumpdev $sw $todev >/dev/null 2>&1
  		if [ "$?" -eq 1 ]	
  		then echo "\
Could not change the dump device temporarily to $todev."
			# This will likely fail later.
		fi
	fi # end of -n $sw

	tctl -f $dumpdev reset
	bsize=`lsattr -a block_size -El $basdumpdev | awk '{print $2}'`
	[[ $bsize -eq 0 ]] && bsize=65536
	blks=`expr "(" $dumpsize + $bsize - 1 ")" / $bsize`
	string=""
	# If the dump isn't compressed, compress it.
	# Otherwise, don't, and this is pass 2 by the way.
	if [ $uncdumpsize = 0 ]
	then 
	    cmd="dd if=$dumpdev bs=$bsize count=$blks |compress > $snapdir/dump.Z"
	else
	    check_compress_header $dumpdev
	    tape_compressed_file=
	    if [ "$compress_header" == 1 -o "$compress_header" == 2 ]
	    then
		tape_compressed_file="dump.Z"
	      else if [ "$compress_header" == 3 -o "$compress_header" == 4 ]
	      then
		tape_compressed_file="dump.BZ"
	      fi
	    fi
 
	    cmd="dd if=$dumpdev of=$snapdir/$tape_compressed_file bs=$bsize count=$blks"
	fi
	string=$cmd
	run_cmd

	# Snip off excess bytes at end if dump was compressed during phase 1.
	if [ $passno = 2 -a $uncdumpsize = 0 ]
	then	/usr/lib/ras/dumptrunc $snapdir/dump.Z $dumpsize
	fi
			
	[ -n "$sw" ] && sysdumpdev $sw $dumpdev >/dev/null 2>&1

	return 0
}

#
# Get the kdb_64 executable and make a "kdb -> kdb_64" symlink
#
get_kdb() {

  # Get the kdb program.
  kdb_base=kdb_64
  kdbpgm_plat=`whence $kdb_base`
  [[ -z "$kdbpgm_plat" ]] && return

  if [ $passno = 1 ]
  then	# get the size.
	temp_bytes=`ls -l $kdbpgm_plat | awk '{print $5}'`
        total_bytes=`expr $total_bytes + $temp_bytes`
  else	# copy the kdbpgm_plat file and make a local symlink to it.
	string="Copying $kdbpgm_plat"
	cmd="cp -p $kdbpgm_plat $snapdir; (cd $snapdir; ln -s kdb_64 kdb)"
	run_cmd
	# Make links to the dead commands. Must be relative paths!
	save_dir=`pwd`
	cd $snapdir
	string="Creating links for trcdead, errdead, and livedumpdead."
	cmd="\
ln -s $kdb_base trcdead;\
ln -s $kdb_base errdead;\
ln -s $kdb_base livedumpdead"
	run_cmd
	cd $save_dir
  fi
}

# Function state_func6 - capture the dump, unix, et al
state_func6 () {
#            
# 
  comp=dump
  snapfile=$destdir/$comp/$comp.snap
  snapdir=$destdir/$comp
  # dump_size_included is 1 if the dump size has already been added to
  # $total_bytes when we're ready to add it in pass 1.
  dumpsize_included=0
  # There are some conditions under which we can't run adump.
  # if noadump is 1, we won't try the adump.
  noadump=0

  if [ "$passno" = 1 ]
  then
  	echo "Checking space requirement for $comp information\c"
  else
  	echo "Gathering $comp system information\c"
  fi

  # First, remove prior dump
  rm -f $snapdir/dump*

  string="creation date"
  cmd="date >> $snapfile 2>&1"
  run_cmd

  string="uname -a"
  cmd="uname -a >> $snapfile 2>&1"
  run_cmd

  string="sum of /unix"
  cmd="sum /unix >> $snapfile 2>&1"
  run_cmd

  if [ "$bad_unix" != 1 ]
  then
  	string=""
  	cmd="cat /unix | compress > $snapdir/unix.Z"
  	run_cmd
  fi

  string="sysdumpdev -L -v"
  cmd="sysdumpdev -L -v >> $snapfile 2>&1"
  run_cmd

  # Format the minidump from the error log.
  mdmprptout=mdmprpt.out
  string="The formatted minidump is in file $mdmprptout"
  cmd="mdmprpt > $snapdir/$mdmprptout 2>&1"
  run_cmd
  unset mdmprptout

  # Capture the raw minidump in case it was removed from the error log.
  mdfile=/var/adm/ras/minidump_last
  if [ -f $mdfile ]
  then	# file exists
  	string="The raw minidump is in file $mdfile"
  	cmd="cp -p $mdfile $snapdir >/dev/null 2>&1"
  	run_cmd
  fi
  unset mdfile
 
  if [ "$nodumpcollect" = n ]
  then
	  # Get info from the dump.
	  # This sets many variables, see the function above.
	  get_dump_info
	  if [ "$?" -eq 2 ]	
	  then
		nodump=1	
		string="Status of Dump Copy"
		cmd="echo 'No dump was copied because a recent dump does not exist.\n' >> $snapfile 2>&1"
		run_cmd 
		return
	  fi

	  # If the dump is zero bytes, we don't want to
	  # copy it.  Just put out a warning.
	  if [ "$dumpsize" = 0 ]
	  then
		zero_bytes=1
		string="Status of Dump Copy"
		cmd="echo 'The dump was not copied, because the dump that\nwas taken is zero bytes.\n' >> $snapfile 2>&1"
		run_cmd 
		return
	  fi

	  lsps $basdumpdev >/dev/null 2>&1
	  dmptpgsp=$?
	  if [ "$dmptpgsp" = 0 ] 
	  then	dump_from_ps
		[[ $? -ne 0 ]] && return
	  fi

	  if [ "$dmptpgsp" != 0 ]
	  then
		# The dump device is NOT paging space.
		echo $dumpdev | grep "^/" >/dev/null 2>&1
		if [ "$?" -eq 0 ]
		then
		   if [ "$istapdev" -ne 0 ]
		   then	dump_from_tape
			[[ $? -ne 0 ]] && return
		   else if [ "$iscdrdev" -ne 0 ]
				then	dump_from_cdrom
					[[ $? -ne 0 ]] && return
				else	#Dump device is dedicated lv.
				dump_from_local
				[[ $? -ne 0 ]] && return
				fi
		fi
		else
			echo "\
	Attention: no valid dump device can be found."
			return
		fi  	# If dump is local.
	  fi  		# If dump is not paging space.

	  # See if they want adump output.
	  if [ "$doadump" = y ]
	  then
		if [[ $passno = 2 && $noadump = 1 ]]
		then echo "\
	Attention:  adump can't be run against this dump."
		fi
		if [[ $noadump -ne 1 ]]
		then # Do the adump, passes 1 and 2.
		string=""
		cmd="adump -d $snapdir/dump > $snapdir/adump.report"
		run_cmd
		fi
	  fi # end of "if adump" 

	  if [ "$invalid" = 1 -a "$passno" = 2 ]
	  then		
		echo "\nA dump was taken to $dumpdev, but an attempt to copy the dump to\n\
	a file during boot failed.  The dump was copied to an external device.\n\
	To insure that the next system dump will be copied, check that the\n\
	'copy directory' has enough space and that the 'forced copy flag'\n\
	for the sysdumpdev command is set to 'TRUE'.  To check these attributes,\n\
	run the command 'sysdumpdev -l'.\n"
	  fi

	  if [ "$nodump" = 1  -a "$passno" = 2 ]
	  then
		echo "\nNo dump was copied because a recent dump does not exist.\n"
	  fi		

	  if [ "$passno" = 1 -a "$invalid" != 1 -a "$nodump" != 1 -a "$zero_bytes" != 1 -a $istapdev != 1 ]
	  then
		/usr/lib/ras/check_unix $dumpdev 2>&1 >/dev/null
		rc=$?
		# check_unix returns 1 if the dump is ok but doesn't match /unix.
		# It returns a 2 for a compressed dump.
		if [ $rc -eq 1 ]
		then
			bad_unix=1
		fi
		[ $rc -eq 2 ] && echo "\n\
	Attention:  The dump is compressed, and we were not able to verify it is
	consistent with /unix.  Processing continues."
		[[ $dumpsize_included != 1 ]] && total_bytes=`expr $total_bytes + $dumpsize`

	  fi

	  if [ "$passno" = 2 -a "$bad_unix" = 1 ]
	  then
		echo "\nWARNING: The dump and /unix file were not copied.
	The /unix file does not match the latest dump on your
	system.  The /unix must be the same unix, or linked to
	the same unix, that was running when the dump occurred.
	Possible Causes:
	1) The /unix file does not exist.
	2) The dump that was taken is a partial dump.
	3) The /unix file on your system was replaced,
	   and the bosboot command was not run.  If this is the
	   case, then run the bosboot command and reboot your
	   system.\n"
	  fi

	  if [ "$passno" = 2 -a "$zero_bytes" = 1 ]
	  then
		echo "\nWARNING: The dump was not copied, because the dump that\nwas taken is zero bytes.\n"
	  fi
  fi

  # Capture the kdb from this system.
  if [ "$invalid" != 1 -a "$nodump" != 1 -a "$zero_bytes" != 1 -a "$bad_unix" != 1 ]
  then	get_kdb
  fi

  src_dir=/usr/lib/ras/autoload
  if [ -d $src_dir ]; then
       	targ_dir=$snapdir/autoload
       	[ -d $targ_dir ] && rm $targ_dir/* >/dev/null 2>&1
	string=""
	cmd="cp -p $src_dir/* $targ_dir >/dev/null 2>&1"
	run_cmd
  fi

  echo " done."
} # End of state_func6

# Function state_func7
state_func7 () {
#            
# 
  comp=sna
  snapfile=$destdir/$comp/$comp.snap
  snapdir=$destdir/$comp

  if [ "$passno" = 1 ]
  then
  	echo "Checking space requirement for $comp information\c"
  else
  	echo "Gathering $comp system information\c"
  fi


  string="creation date"
  cmd="date >> $snapfile 2>&1"
  run_cmd

  if [ -f /usr/bin/snagetpd ]
  then
      string="See file pd.tar.Z"
      cmd="snagetpd -q $snapdir/pd > $snapdir/snagetpd.out 2>&1"
      run_cmd
  fi

  string=""
  cmd="cp -p /usr/lpp/devices.mca.efc3/tools/getchanpd $snapdir/getchanpd.efc3 >/dev/null 2>&1"
  run_cmd

  string=""
  cmd="cp -p /usr/lpp/devices.pci/esconCU/bin/getchanpd $snapdir/getchanpd.pci >/dev/null 2>&1"
  run_cmd
 
  if [ -r /etc/objrepos/X25xlate ]
  then
        string=""
	cmd="odmget X25xlate > $snapdir/X25xlate.add >/dev/null 2>&1"
	run_cmd
  fi

  filelist=`ls /var/sna`
  for file in $filelist
  do
	if [ ! -d "/var/sna/$file" ] 
	then
		string=""
		cmd="cp -p /var/sna/$file $snapdir >/dev/null 2>&1"
		run_cmd
	fi
  done

  echo " done."

} # End of state_func7

# Function state_func8
state_func8 () {
#            
# 
  comp=filesys
  snapfile=$destdir/$comp/$comp.snap
  snapdir=$destdir/$comp

  if [ "$passno" = 1 ]
  then
  	echo "Checking space requirement for $comp information\c"
  else
  	echo "Gathering $comp system information\c"
  fi


  string="creation date"
  cmd="date >> $snapfile 2>&1"
  run_cmd

  string="df -k"
  cmd="df -k >> $snapfile 2>&1"
  run_cmd

  string="mount"
  cmd="mount >> $snapfile 2>&1"
  run_cmd

  string="lsfs -q"
  cmd="lsfs -q >> $snapfile 2>&1"
  run_cmd

  for j in `lsfs -v jfs2 | awk '{print $1}' | tail +2`
  do
    string="snapshot -q $j"
    cmd="snapshot -q $j >> $snapfile 2>&1"
    run_cmd
  done

  string="lsvg -o"
  cmd="lsvg -o >> $snapfile 2>&1"
  run_cmd

  for j in `lsvg -o`
  do
    string="lsvg -p $j"
    cmd="lsvg -p $j >> $snapfile 2>&1"
    run_cmd
  done

  string="lsvg -o| xargs lsvg -l"
  cmd="lsvg -o| xargs lsvg -l >> $snapfile 2>&1"
  run_cmd

  for j in `lsdev -Cc disk -F name`
  do
    string="lspv -l $j"
    cmd="lspv -l $j >> $snapfile 2>&1"
    run_cmd
  done

  # See if lsvg -o will give any output.
  j=`lsvg -o | head -1 | wc -l`
  if [[ "$j" -ne '0' ]] then
    for j in `lsvg -o|lsvg -i -l|grep -v "MOUNT POINT"|grep -v ":"| awk '{print $1}'`
    do
      string="lslv -l $j"
      cmd="lslv -l $j >> $snapfile 2>&1"
      run_cmd
    done
  fi

  for j in `lsdev -Cc disk -F name`
  do
    string="lsattr -El $j"
    cmd="lsattr -El $j >> $snapfile 2>&1"
    run_cmd
  done

  echo " done."


} # End of state_func8

# Function state_func9
state_func9 () {
#            
# 
  comp=async
  snapfile=$destdir/$comp/$comp.snap
  snapdir=$destdir/$comp 

  if [ "$passno" = 1 ]
  then
  	echo "Checking space requirement for $comp information\c"
  else
  	echo "Gathering $comp system information\c"
  fi


  string="creation date"
  cmd="date >> $snapfile 2>&1"
  run_cmd
  
  string="Note: If you want the /var/adm/ras/trcfile, snap -g will get it"
  cmd=""
  run_cmd

  string="Slip Interface Configs"
  cmd="lsdev -Cc if -Fname | grep sl | xargs -n1 ifconfig >> $snapfile 2>&1"
  run_cmd

  string="pdisable"
  cmd="pdisable >> $snapfile 2>&1"
  run_cmd

  string="penable"
  cmd="penable >> $snapfile 2>&1"
  run_cmd

  string="pdelay"
  cmd="pdelay >> $snapfile 2>&1"
  run_cmd

  string="pshare"
  cmd="pshare >> $snapfile 2>&1"
  run_cmd

  string="phold"
  cmd="phold >> $snapfile 2>&1"
  run_cmd

  for j in `lsdev -Cc tty -F name`
  do
    string="lsattr -El $j"
    cmd="lsattr -El $j >> $snapfile 2>&1"
    run_cmd
  done

  if [ -d /etc/uucp ]
  then
	string=""
  	cmd="cp -p /etc/uucp/Devices $snapdir >/dev/null 2>&1"
	run_cmd

	string=""
  	cmd="cp -p /etc/uucp/Dialcodes $snapdir >/dev/null 2>&1"
	run_cmd

	string=""
  	cmd="cp -p /etc/uucp/Dialers $snapdir >/dev/null 2>&1"
	run_cmd

	string=""
  	cmd="cp -p /etc/uucp/Maxuuscheds $snapdir >/dev/null 2>&1"
	run_cmd

	string=""
  	cmd="cp -p /etc/uucp/Maxuuxqts $snapdir >/dev/null 2>&1"
	run_cmd

	string=""
  	cmd="cp -p /etc/uucp/Permissions $snapdir >/dev/null 2>&1"
	run_cmd

	string=""
  	cmd="cp -p /etc/uucp/Poll $snapdir >/dev/null 2>&1"
	run_cmd

	string=""
  	cmd="cp -p /etc/uucp/Systems $snapdir >/dev/null 2>&1"
	run_cmd
  fi
  echo " done."

} # End of state_func9

# Function state_func10
# Gather programming language information
state_func10 () {
#            
# 
  comp=lang
  snapfile=$destdir/$comp/$comp.snap

  if [ "$passno" = 1 ]
  then
  	echo "Checking space requirement for $comp information\c"
  else
  	echo "Gathering $comp system information\c"
  fi


  string="creation date"
  cmd="date >> $snapfile 2>&1"
  run_cmd

  string="env"
  cmd="env >> $snapfile 2>&1"
  run_cmd

  # C Compiler
  lslpp -h vac* >/dev/null 2>&1
  if [ "$?" -eq 0 ]
  then
        string="lslpp -h vac*"
        cmd="lslpp -h vac* >> $snapfile 2>&1"
        run_cmd
  fi  

  # xlf Compiler		
  lslpp -h xlf* >/dev/null 2>&1 

  if [ "$?" -eq 0 ]
  then
	string="lslpp -h xlf*"
	cmd="lslpp -h xlf* >> $snapfile 2>&1"
	run_cmd
  fi

  # xlp Compiler		
  lslpp -h xlp* >/dev/null 2>&1 

  if [ "$?" -eq 0 ]
  then
	string="lslpp -h xlp*"
	cmd="lslpp -h xlp* >> $snapfile 2>&1"
	run_cmd
  fi

  # xlC Compiler		
  lslpp -h xlC* >/dev/null 2>&1 

  if [ "$?" -eq 0 ]
  then
	string="lslpp -h xlC*"
	cmd="lslpp -h xlC* >> $snapfile 2>&1"
	run_cmd
  fi

  # C++ Compiler
  lslpp -h vacpp* >/dev/null 2>&1

  if [ "$?" -eq 0 ]
  then
        string="lslpp -h vacpp*"
        cmd="lslpp -h vacpp* >> $snapfile 2>&1"
        run_cmd
  fi  

  # IBM C and C++  Compiler
  lslpp -h ibmcxx* >/dev/null 2>&1

  if [ "$?" -eq 0 ]
  then
        string="lslpp -h ibmcxx*"
        cmd="lslpp -h ibmcxx* >> $snapfile 2>&1"
        run_cmd
  fi   
  
  string="lslpp -h vatools.*"
  cmd="lslpp -h vatools.* >> $snapfile 2>&1"
  run_cmd 

  string="lslpp -h xlsmp.*"
  cmd="lslpp -h xlsmp.* >> $snapfile 2>&1"
  run_cmd 
 
  string="lslpp -h INMSearch.*" 
  cmd="lslpp -h INMSearch.* >> $snapfile 2>&1" 
  run_cmd 
 
  string="lslpp -h ifor_ls.*" 
  cmd="lslpp -h ifor_ls.* >> $snapfile 2>&1" 
  run_cmd 
  
  string="lslpp -h bos.rte.ifor_ls.*" 
  cmd="lslpp -h bos.rte.ifor_ls.* >> $snapfile 2>&1" 
  run_cmd 
 
  string="lslpp -h idebug.*" 
  cmd="lslpp -h idebug.* >> $snapfile 2>&1" 
  run_cmd 

  string="lslpp -h bos.adt.*" 
  cmd="lslpp -h bos.adt.* >> $snapfile 2>&1" 
  run_cmd

  # COBOL Compiler
  lslpp -h cobol* >/dev/null 2>&1 

  if [ "$?" -eq 0 ]
  then
	string="lslpp -h cobol*"
	cmd="lslpp -h cobol* >> $snapfile 2>&1"
	run_cmd
  fi

  # COBOL Compiler

  echo " done."

} # End of state_func10


# Function state_func11
state_func11 () {
#
#
  comp=XS25
  snapfile=$destdir/$comp/$comp.snap
  snapdir=$destdir/$comp

  if [ "$passno" = 1 ]
  then
        echo "Checking space requirement for $comp information\c"
  else
        echo "Gathering $comp system information\c"
  fi

  string="creation date"
  cmd="date >> $snapfile 2>&1"
  run_cmd

# Get all streams modules what/sum information

  for i in x25frm psw pktsw dsw x25hdlc
   do
        string="what /usr/lib/drivers/pse/$i"
        cmd="what /usr/lib/drivers/pse/$i >> $snapfile 2>&1"
        run_cmd

        string="sum /usr/lib/drivers/pse/$i"
        cmd="sum /usr/lib/drivers/pse/$i >> $snapfile 2>&1"
        run_cmd
   done

  x=`ps -ef | grep xotaddrd |grep -v grep | awk '{print $8}'|wc -l`

     if [ $x = 1 ]
     then
          string="xotdisplay -n"
          cmd="xotdisplay -n >> $snapfile 2>&1"
          run_cmd

          string="xotdisplay"
          cmd="xotdisplay >> $snapfile 2>&1"
          run_cmd

          string="xotstat -l all"
          cmd="xotstat -l all >> $snapfile 2>&1"
          run_cmd
     fi

  string="what /usr/lib/drivers/pse/xol"
  cmd="what /usr/lib/drivers/pse/xol >> $snapfile 2>&1"
  run_cmd

  string="sum /usr/lib/drivers/pse/xol"
  cmd="sum /usr/lib/drivers/pse/xol >> $snapfile 2>&1"
  run_cmd

  string="what /usr/lib/drivers/pse/xot"
  cmd="what /usr/lib/drivers/pse/xot >> $snapfile 2>&1"
  run_cmd

  string="sum /usr/lib/drivers/pse/xot"
  cmd="sum /usr/lib/drivers/pse/xot >> $snapfile 2>&1"
  run_cmd

  string="what /usr/lib/drivers/pse/x25pkt"
  cmd="what /usr/lib/drivers/pse/x25pkt >> $snapfile 2>&1"
  run_cmd

  string="sum /usr/lib/drivers/pse/x25pkt"
  cmd="sum /usr/lib/drivers/pse/x25pkt >> $snapfile 2>&1"
  run_cmd

  string="what /usr/lib/drivers/pse/twd"
  cmd="what /usr/lib/drivers/pse/twd >> $snapfile 2>&1"
  run_cmd

  string="sum /usr/lib/drivers/pse/twd"
  cmd="sum /usr/lib/drivers/pse/twd >> $snapfile 2>&1"
  run_cmd

  string="what /usr/lib/drivers/pse/ciox25"
  cmd="what /usr/lib/drivers/pse/ciox25 >> $snapfile 2>&1"
  run_cmd

  string="sum /usr/lib/drivers/pse/ciox25"
  cmd="sum /usr/lib/drivers/pse/ciox25 >> $snapfile 2>&1"
  run_cmd

  string="what /usr/lib/drivers/pse/npi"
  cmd="what /usr/lib/drivers/pse/npi >> $snapfile 2>&1"
  run_cmd

  string="sum /usr/lib/drivers/pse/npi"
  cmd="sum /usr/lib/drivers/pse/npi >> $snapfile 2>&1"
  run_cmd

  string="what /usr/lib/drivers/pse/if_xs"
  cmd="what /usr/lib/drivers/pse/if_xs >> $snapfile 2>&1"
  run_cmd

  string="sum /usr/lib/drivers/pse/if_xs"
  cmd="sum /usr/lib/drivers/pse/if_xs >> $snapfile 2>&1"
  run_cmd

  if [ -e /usr/lib/drivers/pse/if_xsV52 ]
  then

    string="what /usr/lib/drivers/pse/if_xsV52"
    cmd="what /usr/lib/drivers/pse/if_xsV52 >> $snapfile 2>&1"
    run_cmd

    string="sum /usr/lib/drivers/pse/if_xsV52"
    cmd="sum /usr/lib/drivers/pse/if_xsV52 >> $snapfile 2>&1"
    run_cmd
  fi

  string="what /usr/lib/drivers/pse/pad"
  cmd="what /usr/lib/drivers/pse/pad >> $snapfile 2>&1"
  run_cmd

  string="sum /usr/lib/drivers/pse/pad"
  cmd="sum /usr/lib/drivers/pse/pad >> $snapfile 2>&1"
  run_cmd

  string="what /usr/lib/drivers/pse/x29"
  cmd="what /usr/lib/drivers/pse/x29 >> $snapfile 2>&1"
  run_cmd

  string="sum /usr/lib/drivers/pse/x29"
  cmd="sum /usr/lib/drivers/pse/x29 >> $snapfile 2>&1"
  run_cmd

  string="what /usr/lib/drivers/pse/x25dump"
  cmd="what /usr/lib/drivers/pse/x25dump >> $snapfile 2>&1"
  run_cmd

  string="sum /usr/lib/drivers/pse/x25dump"
  cmd="sum /usr/lib/drivers/pse/x25dump >> $snapfile 2>&1"
  run_cmd

  string="what /usr/lib/drivers/pse/loop"
  cmd="what /usr/lib/drivers/pse/loop >> $snapfile 2>&1"
  run_cmd

  string="sum /usr/lib/drivers/pse/loop"
  cmd="sum /usr/lib/drivers/pse/loop >> $snapfile 2>&1"
  run_cmd

# Get all daemon information for X.25 LPP
  string="what /usr/lib/drivers/pse/x25linkd"
  cmd="what /usr/lib/drivers/pse/x25linkd >> $snapfile 2>&1"
  run_cmd

  string="sum /usr/lib/drivers/pse/x25linkd"
  cmd="sum /usr/lib/drivers/pse/x25linkd >> $snapfile 2>&1"
  run_cmd

  string="what /usr/lib/drivers/pse/x25d"
  cmd="what /usr/lib/drivers/pse/x25d >> $snapfile 2>&1"
  run_cmd

  string="sum /usr/lib/drivers/pse/x25d"
  cmd="sum /usr/lib/drivers/pse/x25d >> $snapfile 2>&1"
  run_cmd

  string="what /usr/lib/drivers/pse/x29d"
  cmd="what /usr/lib/drivers/pse/x29d >> $snapfile 2>&1"
  run_cmd

  string="sum /usr/lib/drivers/pse/x29d"
  cmd="sum /usr/lib/drivers/pse/x29d >> $snapfile 2>&1"
  run_cmd

# Get all adapter software information

  string="what /usr/lib/asw/sx25cyc.cod"
  cmd="what /usr/lib/asw/sx25cyc.cod >> $snapfile 2>&1"
  run_cmd

  string="what /usr/lib/asw/sx25pma.cod"
  cmd="what /usr/lib/asw/sx25pma.cod >> $snapfile 2>&1"
  run_cmd

  string="sum /usr/lib/asw/sx25cyc.cod"
  cmd="sum /usr/lib/asw/sx25cyc.cod >> $snapfile 2>&1"
  run_cmd

  string="sum /usr/lib/asw/sx25pma.cod"
  cmd="sum /usr/lib/asw/sx25pma.cod >> $snapfile 2>&1"
  run_cmd

  for i in sx25dbg.cod sx25a960.rel sx25a960hx.rel
  do
    string="ls -l /usr/lib/asw/$i"
    cmd="ls -l /usr/lib/asw/$i >> $snapfile 2>&1"
    run_cmd

    string="what /usr/lib/asw/$i"
    cmd="what /usr/lib/asw/$i >> $snapfile 2>&1"
    run_cmd

    string="sum /usr/lib/asw/$i"
    cmd="sum /usr/lib/asw/$i >> $snapfile 2>&1"
    run_cmd
  done

# Get all X.25 LPP command information

  string="what /usr/sbin/x25ip"
  cmd="what /usr/sbin/x25ip >> $snapfile 2>&1"
  run_cmd

  string="sum /usr/sbin/x25ip"
  cmd="sum /usr/sbin/x25ip >> $snapfile 2>&1"
  run_cmd

  string="what /usr/lib/libx25s.a"
  cmd="what /usr/lib/libx25s.a >> $snapfile 2>&1"
  run_cmd
 
  string="sum /usr/lib/libx25s.a"
  cmd="sum /usr/lib/libx25s.a >> $snapfile 2>&1"
  run_cmd

  string="what /usr/bin/xtalk"
  cmd="what /usr/bin/xtalk >> $snapfile 2>&1"
  run_cmd

  string="sum /usr/bin/xtalk"
  cmd="sum  /usr/bin/xtalk >> $snapfile 2>&1"
  run_cmd

  string="what /usr/sbin/xroute"
  cmd="what /usr/sbin/xroute >> $snapfile 2>&1"
  run_cmd

  string="sum /usr/sbin/xroute"
  cmd="sum /usr/sbin/xroute >> $snapfile 2>&1"
  run_cmd

  string="what /usr/sbin/x25smuxd"
  cmd="what /usr/sbin/x25smuxd >> $snapfile 2>&1"
  run_cmd

  string="sum /usr/sbin/x25smuxd"
  cmd="sum /usr/sbin/x25smuxd >> $snapfile 2>&1"
  run_cmd

  string="what /usr/sbin/x25smuxd.defs"
  cmd="what /usr/sbin/x25smuxd.defs >> $snapfile 2>&1"
  run_cmd

  string="sum /usr/sbin/x25smuxd.defs"
  cmd="sum /usr/sbin/x25smuxd.defs >> $snapfile 2>&1"
  run_cmd

  string="what /usr/bin/x25mon"
  cmd="what /usr/bin/x25mon >> $snapfile 2>&1"
  run_cmd
  string="sum /usr/bin/x25mon"
  cmd="sum /usr/bin/x25mon >> $snapfile 2>&1"
  run_cmd

  string="what /usr/bin/backupx25"
  cmd="what /usr/bin/backupx25 >> $snapfile 2>&1"
  run_cmd
  string="sum /usr/bin/backupx25"
  cmd="sum /usr/bin/backupx25 >> $snapfile 2>&1"
  run_cmd

  string="what /usr/bin/chsx25"
  cmd="what /usr/bin/chsx25 >> $snapfile 2>&1"
  run_cmd
  string="sum /usr/bin/chsx25"
  cmd="sum /usr/bin/chsx25 >> $snapfile 2>&1"
  run_cmd

  string="what /usr/bin/lsx25"
  cmd="what /usr/bin/lsx25 >> $snapfile 2>&1"
  run_cmd
  string="sum /usr/bin/lsx25"
  cmd="sum /usr/bin/lsx25 >> $snapfile 2>&1"
  run_cmd

  string="what /usr/bin/x25status"
  cmd="what /usr/bin/x25status >> $snapfile 2>&1"
  run_cmd
  string="sum /usr/bin/x25status"
  cmd="sum /usr/bin/x25status >> $snapfile 2>&1"
  run_cmd


  string="what /usr/bin/mksx25"
  cmd="what /usr/bin/mksx25 >> $snapfile 2>&1"
  run_cmd
  string="sum /usr/bin/mksx25"
  cmd="sum /usr/bin/mksx25 >> $snapfile 2>&1"
  run_cmd

  string="what /usr/bin/removex25"
  cmd="what /usr/bin/removex25 >> $snapfile 2>&1"
  run_cmd
  string="sum /usr/bin/removex25"
  cmd="sum /usr/bin/removex25 >> $snapfile 2>&1"
  run_cmd

  string="what /usr/bin/restorex25"
  cmd="what /usr/bin/restorex25 >> $snapfile 2>&1"
  run_cmd
  string="sum /usr/bin/restorex25"
  cmd="sum /usr/bin/restorex25 >> $snapfile 2>&1"
  run_cmd

  string="what /usr/bin/rmsx25"
  cmd="what /usr/bin/rmsx25 >> $snapfile 2>&1"
  run_cmd
  string="sum /usr/bin/restorex25"
  cmd="sum /usr/bin/restorex25 >> $snapfile 2>&1"
  run_cmd

  string="what /usr/bin/rmsx25"
  cmd="what /usr/bin/rmsx25 >> $snapfile 2>&1"
  run_cmd
  string="sum /usr/bin/rmsx25"
  cmd="sum /usr/bin/rmsx25 >> $snapfile 2>&1"
  run_cmd

  string="what /usr/bin/sx25debug"
  cmd="what /usr/bin/sx25debug >> $snapfile 2>&1"
  run_cmd
  string="sum /usr/bin/sx25debug"
  cmd="sum /usr/bin/sx25debug >> $snapfile 2>&1"
  run_cmd

#Get configuration information on X.25 LPP
  string="x25ip -s "
  cmd="x25ip -s >> $snapfile 2>&1"
  run_cmd

  string="lsx25"
  cmd="lsx25 >> $snapfile 2>&1"
  run_cmd

  string="x25status"
  cmd="x25status >> $snapfile 2>&1"
  run_cmd

  string="scls"
  cmd="scls >> $snapfile 2>&1"
  run_cmd

  string="strinfo -m"
  cmd="strinfo -m >> $snapfile 2>&1"
  run_cmd

  string="strinfo -q"
  cmd="strinfo -q >> $snapfile 2>&1"
  run_cmd

  string="lsdev -C"
  cmd="lsdev -C >> $snapfile 2>&1"
  run_cmd

  string="backupx25 -fd /tmp/ibmsupt/XS25"
  cmd="backupx25 -fd /tmp/ibmsupt/XS25 >> $snapfile 2>&1"
  run_cmd

  string="xroute config"
  cmd="cat /etc/xrt.names >> $snapfile 2>&1"
  run_cmd

  string="ps -ef"
  cmd="ps -ef >> $snapfile 2>&1"
  run_cmd

  string="lslpp -l"
  cmd="lslpp -l >> $snapfile 2>&1"
  run_cmd

  if [ "$passno" = 2 ]
  then
  echo "\n"
  echo "For all of the information below put this data in $destdir/other"
  echo "\n"
  echo "GET X.25 PROFILES:"
  echo "Please obtain all X.25 frame and packet layer configuration settings"
  echo "for DCE [i.e. system the workstation is connected to]. This cannot"
  echo "be done by snap. Contact your X.25 administrator for assistance."
  echo " "
  echo "Provide a copy of the Network Subscription."
  echo "   NOTE:This is a document [usually 1 or 2 pages in length] that"
  echo "   describes exactly what the customer has purchased from the"
  echo "   Network Provider.  Network Providers are companies such as"
  echo "   Telenet, Tymnet, GTE, etc.."
  echo " "
  echo " "
  echo "If you are participating in a Beta test program then please make that"
  echo "clear in the file sent with the traces."
  echo " "
  echo "NOTE:  You should collect the X.25 traces as follows:"
  echo " "
  echo "           A. Start the trace"
  echo "           B. Recreate the Problem"
  echo "           C. Stop the trace"
  echo "           D. Gather the trace data"
  echo " "
  echo "    IT IS IMPORTANT THAT YOU START ALL THE TRACES BEFORE"
  echo "    YOU RECREATE THE PROBLEM AND STOP THEM ALL AT THE SAME TIME"
  echo "    IMMEDIATELY AFTER RECREATING THE PROBLEM. THIS ENSURES US THAT "
  echo "    WE ARE GOING TO BE LOOKING AT RELATED TRACES."
  echo " "
  echo "CLEAR THE SYSTEM ERROR LOGS:"
  echo "      # errclear 0"
  echo " "
  echo "START THE X25MON TRACE:"
  echo "     # x25mon -fpct -n port_name > $destdir/other/x25mon.port_name 1 &"

  echo "            where port_name is the name of the x25 port [eg. sx25a1]"
  echo "            Run one for each port in question"
  echo " "
  echo "START X.25 TRACE:"
  echo "      # trace -a -T 500000 -L 10000000 -j 25C,329,32A,32B,32C,33B,33C,41F,2D8,41E,29F,3A9,3AA,3AB"
  echo "         Note:  If there is a a significant amount of X.25 data traffic"
  echo "           the -T and -L values may need to be increased."
  echo "
  echo "         Hookid values:"
  echo "           25C SX25_PKT"
  echo "           329 SX25_IF"
  echo "           32A SX25_NPI"
  echo "           32B SX25_ETC"
  echo "           32C SX25_PAD"
  echo "           33B SX25_COMIO "
  echo "           33C SX25_TWD"
  echo "           41F SX25_PERF"
  echo "           2D8 SX25_FRM"
  echo "           41E SX25_HDLC"
  echo "           29F ddricio"
  echo "           3A9 dpmpdd"
  echo "           3AA dpmpdd"
  echo "           3AB dpmpdd"

  echo "      It might be that when working a problem with AIX support, a"
  echo "      subset of these trace hooks is asked for."
  echo " "
  echo "RECREATE THE PROBLEM:"
  echo " "
  echo "  STOP THE TRACE:"
  echo "   # trcstop"
  echo " "
  echo "  STOP THE X25MON TRACE:"
  echo "     #  ps -e |grep x25mon"
  echo "     #  kill -9 <PID for x25mon>"
  echo " "
  echo "  GATHER MICROCODE TRACE"
  echo "  # sx25debug -b # | tee $destdir/other/sx25debug.board#"
  echo "    where # is the board to be traced"
  echo " "
  echo "COLLECT THE DATA:"
  echo "    The following is a set of instructions on how to"
  echo "    collect the data that you have just gathered."
  echo " "
  echo "  CREATE A FILE $destdir/other/README.PROBLEM that"
  echo "          a) describes the problem in detail"
  echo "             What happens?"
  echo "             What do you expect to happen?"
  echo "             What are the steps to recreate the problem?"
  echo "          b) lists customer & SE/support contacts with phone numbers"
  echo "          c) describes your network - a diagram from DTE to DCE"
  echo "          d) lists non-IBM X.25 applications running & who to contact"
  echo "             for technical support"
  echo " "
  echo "  GET A SYSTEM ERROR REPORT:"
  echo "      # errpt -a > $destdir/other/errlog"
  echo " "
  echo "  GET DEVICE DRIVER TRACE FILE:"
  echo " "
 fi
  echo "done."

} # End of state_func11

#Function state_func12
state_func12()                  # function to gather RSCT data.
{

 if [ -x /usr/sbin/rsct/bin/ctsnap ]
 then
        /usr/sbin/rsct/bin/ctsnap  -d $destdir/ctsupt
 fi

} # End of state_func12

# Function state_func102
state_func102 () {
# 
  echo "\nCreating compressed pax file... "
#  echo "Changing directory to $destdir... "
  cd $destdir >/dev/null 2>&1
  if [ "$?" != 0 ]
  then
        echo " snap: Encountered an error.  Suspect $destdir does not exist."
        echo "snap: Please gather the information first.\n"
        exit 16
  fi

  cd $destdir/other > /dev/null 2>&1
  if [ "$?" != 0 ]
  then
        echo " snap: Can't find the snap information."
        echo "snap: Please gather the information first.\n"
        exit 17
  fi
  cd $destdir > /dev/null 2>&1

  echo "Starting pax/compress process... Please wait...\c"

  snapscripts=`/usr/bin/ls /usr/lib/ras/snapscripts`
  dirlist="$complist $snapscripts testcase other"
  totaldirs=""
  for dirs in $dirlist
  do
	[ -d "$destdir/$dirs" ] && totaldirs="$totaldirs ./$dirs"
  done

  # collect the log file.
  [ -f "./script.log" ] && totaldirs="$totaldirs ./script.log"

  # ./general/nim directory already traversed, exclude from 'totaldirs' list
  totaldirs=`echo $totaldirs | awk '{gsub("./general/nim",""); print $0}'`

  if [ -h dump/dump ] || [ -h dump/dump.Z ] || [ -h dump/dump.BZ ] || [ -h dump/dump_file ]
     # There should be a symbolic link, if the dump is on host machine
  then
        if [ -e dump/dump ]
        then

                dump_linkname=`ls -al dump/dump | awk '{print $11}'`    #get the link name
                dump_filename=./dump/dump

        else
                if [  -e dump/dump.Z ]
                then

                        dump_linkname=`ls -al dump/dump.Z | awk '{print $11}'` #get the link name
                        dump_filename=./dump/dump.Z

                else 
			if [  -e dump/dump.BZ ]
			then
				dump_linkname=`ls -al dump/dump.BZ | awk '{print $11}'` #get the link name
				dump_filename=./dump/dump.BZ
			else
                        	dump_linkname=`ls -al dump/dump_file | awk '{print $11}'` #get the link name
                        	dump_filename=./dump/dump_file
                	fi
		fi
        fi

        # remove dump file link  temporarily
        unlink $dump_filename

        #create archive on device
        pax -xpax -s"?$dump_linkname?$dump_filename?" -w  $totaldirs $dump_linkname |  compress > $destdir/snap.pax.Z

        #relink for future use
        ln -fs $dump_linkname $destdir/$dump_filename


  else # Either dump is in $destdir or user didn't ask dump to be copied

        # write to device
        pax -xpax -w  $totaldirs | compress  > $destdir/snap.pax.Z

  fi

  if [ "$?" = 1 ]
  then
        echo " snap: Encountered an error.  Removing snap.*pax.Z* file."
        rm -f  snap.*pax.Z* > /dev/null 2>&1
        echo " snap: Exiting utility."
        exit 18
  fi
  echo " done."
  echo ""

  if [ "$dosplit" = "y" ]
  then
      # split snap.pax.Z if -O option specified, otherwise leave unsplit
      splitsnapfile
  fi

  ls -ln snap.*pax.Z*
} # End of state_func102


# Function: splitsnapfile
splitsnapfile()
{
    snapsize=`ls -l snap.pax.Z | awk -F ' ' '{print $5}'`
    if [ $splitsize -lt $snapsize ]
    then

	# call snapsplit utility to split the snap file.
	let splitsize=$splitsize/1048576
	/usr/sbin/snapsplit -s $splitsize
	if [ ! "$?" = 0 ]
	then
	    echo "There was an error while splitting the snap file"
	fi

    else
	echo "Output file is smaller than split size, it will not be split"
    fi

} # End of splitsnapfile



# Function state_func103
state_func103 () {
#
#
#  echo "\nChanging directory to $destdir... "
  cd $destdir >/dev/null 2>&1
  if [ "$?" != 0 ]
  then
        echo " snap: Encountered an error.  Suspect $destdir does not exist."
        echo "snap: Please gather the information first.\n"
        exit 19
  fi

  cd $destdir/other > /dev/null 2>&1
  if [ "$?" != 0 ]
  then
        echo " snap: Can't find the snap information."
        echo "snap: Please gather the information first.\n"
        exit 20
  fi
  cd $destdir > /dev/null 2>&1


  #echo "\nLooking for compressed pax file... \c"
  #if [ -f "snap.pax.Z" ]
  #then   
    #echo "found it." 
  #else
    #echo "\nCouldn't find snap.pax.Z file in specified directory."
    #exit 2
  #fi

  echo "\nCopying information to $devtype... Please wait...\c"
  dirlist="$complist testcase other"
  totaldirs=""
  for dirs in $dirlist
  do
	[ -d "$destdir/$dirs" ] && totaldirs="$totaldirs ./$dirs"
  done

  # ./general/nim directory already traversed, exclude from 'totaldirs' list
  totaldirs=`echo $totaldirs | awk '{gsub("./general/nim",""); print $0}'`

  # Set the blocksize flag if $blksz specified.
  if [[ -n "$blksz" ]] 
  then	blkflg=-b$blksz
  else	blkflg=
  fi

  if [ -h dump/dump ] || [ -h dump/dump.Z ] || [ -h dump/dump.BZ ] || [ -h dump/dump_file ]
      # There should be a symbolic link, if the dump is on host machine
  then
        if [ -e dump/dump ]
        then

                dump_linkname=`ls -al dump/dump | awk '{print $11}'`    #get the link name
                dump_filename=./dump/dump

        else
                if [  -e dump/dump.Z ]
                then

                        dump_linkname=`ls -al dump/dump.Z | awk '{print $11}'` #get the link name
                        dump_filename=./dump/dump.Z

                else
			if [ -e dump/dump.BZ ]
			then
				dump_linkname=`ls -al dump/dump.BZ | awk '{print $11}'` #get the link name
				dump_filename=./dump/dump.BZ
			else
                        	dump_linkname=`ls -al dump/dump_file | awk '{print $11}'` #get the link name
                        	dump_filename=./dump/dump_file
			fi
                fi

        fi

        # remove dump file link  temporarily
        unlink $dump_filename

        #create archive on device
        pax -xpax -s"?$dump_linkname?$dump_filename?" -wf$devtype $blkflg $totaldirs $dump_linkname

        #relink for future use
        ln -fs $dump_linkname $destdir/$dump_filename



  else # Either dump is in $destdir or user didn't ask dump to be copied

        # write to device
        pax -xpax -wf$devtype $blkflg $totaldirs

  fi


  if [ "$?" != 0 ]
  then
        echo "\n*****"
        echo "***** Problem encountered while attempt to send output to device."
        echo "*****"
        echo "***** Please correct problem."
        echo "***** When problem corrected, run ' snap -o$devtype [-d] '\n"
        exit 21
  fi

  echo " done."
  echo "\n****************************************************************"
  echo "******"
  echo "****** Please Write-Protect the output device now..."
  echo "******"
  echo "****************************************************************"

  if [ "$tape" = y ]
  then
    echo ""
    echo "****************************************************************"
    echo "******"
    echo "****** Please label your tape(s) as follows:"
    echo "****** snap                    blocksize=$blksz"
    echo "****** problem: xxxxx          `date`"
    echo "****** 'your name or company's name here'"
    echo "******"
    echo "****************************************************************"
  else
    echo "****************************************************************"
    echo "******"
    echo "****** Please label your DVD(s) as follows:"
    echo "****** snap                    "
    echo "****** problem: xxxxx          `date`"
    echo "******     'your name or company's name here'"
    echo "******                                       DVD xx of xx"
    echo "****************************************************************"
  fi

} # End of state_func103


# Function state_func104
state_func104 () {
# Cleanup function.  
        found=""
	snapscripts=`ls /usr/lib/ras/snapscripts`
        dflist="async wpars filesys dump general kernel lang other printer sna tcpip testcase XS25 install ssa scraid lvm wlm hacmp pcixscsi sissas ctsupt products IB $snapscripts script.log snap.pax snap.pax.Z flash liveupdate history perf"
        for i in $dflist
        do
                if [ -a "$destdir/$i" ]
                then
                	found=$found"$destdir/$i "
                fi
        done
        if [ -n "$found" ]
        then
          echo "\nThe following directories and files will be deleted:"
          echo "-----------------------------------------------------------"
	  for i in $found
	  do # Enumerate those about to die.
	    echo "$i \c"
	    if [ -d "$i" ]
	    then echo "(directory)"
	    else echo "(file)"
	    fi
	  done

          echo "\nDo you want me to remove these directories (y/n)? \c"
          read jnk
          if [ "$jnk" = y ]
          then
                echo "Removing...\c"
                rm -r $found >/dev/null 2>&1
                echo " done."
                exit 22
          fi
          echo "Aborting deletion process..."
          exit 23
        fi
        echo "Nothing to clean up"
        exit 24

} # End of state_func104


state_func100 () {
# View function
	
snapfile=$destdir/$component/$component.snap

found=n

if [ "$badargs" = n ]
then
	for choice in $complist
	do
		if [ "$component" = "$choice" ]
		then found=y; break;
		fi
	done

	if [ "$found" = y ] 
	then 
		if [ -r "$destdir/$component/$component.snap" ]
		then
			more $destdir/$component/$component.snap 
		else
			echo " snap: $destdir/$component/$component.snap not found"
			exit 25
		fi
	else
		usage
		exit 26
	fi
else
	usage
	exit 27
fi

} # End of state_func100

# Function state_func16
state_func16 () {
#            
# 
  comp=install
  snapfile=$destdir/$comp/$comp.snap

  if [ "$passno" = 1 ]
  then
        echo "Checking space requirement for $comp information...\c"

	let total_bytes=`/usr/lib/instl/install_snap -f $snapfile -QZ`+$total_bytes
  else
        echo "Gathering $comp system information...\c"

  	string=""
	cmd="/usr/lib/instl/install_snap -QFf $snapfile >/dev/null 2>&1"
  	run_cmd
  fi

  echo " done."

} # End of state_func16

# Function state_func17
state_func17 () {
#            
# 

  comp=ssa
  snapdir=$destdir/$comp
  snapfile=$destdir/$comp/$comp.snap
  rm -f $snapfile

  if [ "$passno" = 1 ]
  then
        echo "Checking space requirement for $comp information...\c"

  else
        echo "Gathering $comp system information...\c"

  fi

  string="creation date"
  cmd="date >> $snapfile 2>&1"
  run_cmd
  
  string="Operating System Level"
  cmd="oslevel >> $snapfile 2>&1"
  run_cmd
  
  string="System Software"
  cmd="lslpp -lc | grep SSA >> $snapfile 2>&1"
  run_cmd
  
  string="Router attributes"
  cmd="lsattr -El ssar >> $snapfile 2>&1"
  run_cmd
  
  string="lscfg for SSA Adapters"
  for adap in $(lsdev -Ctssa -Fname) $(lsdev -Ctssa160 -Fname)
  do
    cmd="lscfg -vl $adap >> $snapfile 2>&1 "
    run_cmd
    unset string
  done 
  
  string="cat for SSA Adapters"
  for adap in $(lsdev -Ctssa -Fname) $(lsdev -Ctssa160 -Fname)
  do
    cmd="echo \"\nAdapter $adap\n\" >> $snapfile 2>&1"
    run_cmd
    unset string
    cmd="cat /dev/$adap >> $snapfile 2>&1"
    run_cmd
  done
  
  string="lsattr for all hdisks"
  for disk in $(lsdev -Csssar -thdisk -Fname)
  do
    cmd="echo \"\nDisk $disk\n\" >> $snapfile 2>&1"
    run_cmd
    unset string
    cmd="lsattr -El $disk >> $snapfile 2>&1"
    run_cmd
  done
  
  string="lsdev of all pdisks"
  cmd="lsdev -Csssar -cpdisk >> $snapfile 2>&1"
  run_cmd

  string="lscfg for all pdisks"
  for disk in $(lsdev -Csssar -cpdisk -Fname)
  do
    cmd="lscfg -vl $disk >> $snapfile 2>&1"
    run_cmd
    unset string
  done
  
  string="lsattr for all pdisks"
  for disk in $(lsdev -Csssar -cpdisk -Fname)
  do
    cmd="echo \"\nDisk $disk\n\" >> $snapfile 2>&1"
    run_cmd
    unset string
    cmd="lsattr -El $disk >> $snapfile 2>&1"
    run_cmd
  done

  string="lsdev of all enclosures"
  cmd="lsdev -Cccontainer -sssa >> $snapfile 2>&1"
  run_cmd

  string="lscfg for all enclosures"
  for enclosure in $(lsdev -Cccontainer -sssa -Fname)
  do
    cmd="lscfg -vl $enclosure >> $snapfile 2>&1"
    run_cmd
    unset string
  done

  string="Details of all enclosures"
  for enclosure in $(lsdev -Cccontainer -sssa -Fname)
  do
    cmd="echo \"\nEnclosure $enclosure\n\" >> $snapfile 2>&1"
    run_cmd
    unset string
    cmd="ssaencl -l $enclosure -v -i -b -t -a -f -d -p -o -c >> $snapfile 2>&1"
    run_cmd
  done

  string="Mapping of hdisk to pdisk"
  for i in $(lsdev -Csssar -thdisk -Fname)
  do
    Cssa=$i" ---> "$(ssaxlate -l $i 2>&1)
    cmd="echo \"$Cssa\" >> $snapfile 2>&1" 
    run_cmd
    unset string
  done
  
  string="Mapping of pdisk to hdisk"
  for i in $(lsdev -Csssar -cpdisk -Fname)
  do
    Cssa=$i" ---> "$(ssaxlate -l $i 2>&1)
    cmd="echo \"$Cssa\" >> $snapfile 2>&1" 
    run_cmd
    unset string   
  done
  
  string="connection data"
  for pdisk in $(lsdev -Csssar -cpdisk -Fname)
  do
      for adap in $(ssaadap -l $pdisk 2>/dev/null)
      do
        cmd="ssaconn -l $pdisk -a $adap >> $snapfile 2>&1" 
        run_cmd
        unset string
      done
  done

  string="connection data sorted by link"
  unset Cssa
  for adap in $(lsdev -Ctssa -Fname) $(lsdev -Ctssa160 -Fname)
  do
    cmd="ssa_linksort $adap >> $snapfile 2>&1"
    run_cmd
    unset string
  done
    
  for adap in $(ssaraid -M 2>/dev/null)
  do
    string="SSA Raid Configuration Adapter $adap"
    cmd="ssaraid -l $adap -I >> $snapfile 2>&1"
    run_cmd
  done

  string="Adapter Dump List"
  cmd="ssa_getdump -l >> $snapfile 2>&1"
  run_cmd
  
  if [ "$skipSsaAdapterDumpCollection" = 'no' ]; then

    # This is the adapter dump collection routine.
    # Because this eats disk space, keep it till last, so that if it
    # fills the space left, everything else should have finished.
    #
    string="Adapter Dumps"

    # Collect the pdisk ID and adapter id for each dump available on hot spares
    # As a hot spare can contain many dumps, this list may contain the 
    # same pdisk ID more than once. This list contains an entry for each adapter 
    # dump on a hot spare. Each entry is a two element cut list in the format <pdisk ID>:<adapter ID>
    adapterDumpPdiskList="$(ssa_getdump 2>/dev/null -l -h | awk '{print $4":"$9}')"

    # Re-process the adapter dump pdisk list to ensure only one occurrence of each 
    # pdisk is found. This will ensure the space calculation is for only for the
    # latest adapter dump on a given pdisk. Which is what is eventually collected.
    # If the adapter dump field is blank, the dump is from an adapter that is no longer
    # in the system. This can happen if the adapter is changed or if a hot spare
    # is brought in from another system. At any rate, this occurrence of a dump
    # will be ignored. It is possible another dump on this hot spare will be for an 
    # adapter on this system, so the pdisk may eventually be included.
    uniquePdiskList=''
    for diskAdapterCombo in $adapterDumpPdiskList
    do
      disk=$(echo $diskAdapterCombo | cut -f1 -d':')
      adap=$(echo $diskAdapterCombo | cut -f2 -d':')
      if [ "$adap" != '' ]; then
        checkIfPiskAlreadyInList=$(echo $uniquePdiskList | grep "$disk:")
         if [ "$checkIfPiskAlreadyInList" = '' ]; then
          uniquePdiskList="$uniquePdiskList $diskAdapterCombo"
        fi
      fi
    done
    
    # Process the unique pdisk list to estimate space or collect the latest
    # adapter dump from each hot spare
    typeset -i dsize=0
    for diskAdapterCombo in $uniquePdiskList
    do
      disk=$(echo $diskAdapterCombo | cut -f1 -d':')
      adap=$(echo $diskAdapterCombo | cut -f2 -d':')
      if [ "$passno" = 1 ]
      then
        # get the dump size field returned by ssa_getdump, since there may be multiple
        # dumps, cut off the first field to get a single value
        sizeForDumpsOnPdisk=$(ssa_getdump 2>/dev/null -l -h -d $disk | awk '{print $6}')
        sizeForDumpsOnPdisk=$(echo $sizeForDumpsOnPdisk | cut -f1 -d' ')
	# if ssa_getdump does not return size, set it to 0
	if [ "$sizeForDumpsOnPdisk" = "" ]
	then
		sizeForDumpsOnPdisk=0
	fi
        # assumes 66% compression on dump (1024*334 rather than 1024*1024)
        dsize=$(($sizeForDumpsOnPdisk*334*1024))
        total_bytes=`expr $total_bytes + $dsize`
      else
        dumpfile=$snapdir/ssadump.$adap.$disk
        ssa_getdump 2>/dev/null -c -h -d $disk -a $adap -x -o $dumpfile
        X=$?
        if [ "$X" -eq 0 ]
        then
          compress -f $dumpfile 2>/dev/null
          cmd="echo \"copied $dumpfile.Z\" >> $snapfile 2>&1"
          run_cmd
        else
          cmd="echo \"Failed to copy $dumpfile, Error $X\" >> $snapfile 2>&1"
          run_cmd
        fi
      fi
    done

    if [ "$passno" = 1 ]
    then
      # if we are in this loop, we now there is at least one adapter dump that
      # will be processed. We need to ensure 8MB of space is included in the space required
      # calculation since each adapter dump is captured prior to it's being 
      # compressed. If we do not reserve the 8MB, the dump extraction may fail
      # if the target filesystem does not have sufficient space. Recall, the 
      # previous estimates assume the dump will be compressed, but we cannot
      # compress the dump until it is extracted. Since 66% compression is used
      # above we don't need to add the entire 8MB. We will add only 70% of 8MB.
      # Note: the compression option on ssa_getdump could be used, but it too
      # must have free space. It probably uses /tmp. Better to keep the compression
      # under the control of this script
      total_bytes=`expr $total_bytes + $((8 * 771 * 1024))`
    fi
  fi # end SSA adapter dump collection
  
  echo " done."

} # End of state_func17

state_func18() {  # LVM 
  comp=lvm
  snapfile=$destdir/$comp/$comp.snap
  snapdir=$destdir/$comp

  if [ "$passno" = 1 ]
  then
        echo "Checking space requirement for logical volume manager information\c"
  else
        echo "Gathering logical volume manager information\c"
  fi

  # Once per snap
  snapfile=$snapdir/lvm.snap
  cmd="lspv >> $snapfile 2>&1"; string="lspv"; run_cmd
  cmd="lsvg -o >> $snapfile 2>&1"; string="lsvg -o"; run_cmd
  cmd="ls -l /dev >> $snapfile 2>&1"; string="ls -l /dev"; run_cmd

  snapfile=$snapdir/lvmcfg.log
  cmd="alog -t lvmcfg -o >> $snapfile 2>&1"; string="alog -t lvmcfg -o"; run_cmd
  snapfile=$snapdir/lvmt.log
  cmd="alog -t lvmt -o >> $snapfile 2>&1"; string="alog -t lvmt -o"; run_cmd
  snapfile=$snapdir/lvmgs.log
  cmd="alog -t lvmgs -o >> $snapfile 2>&1"; string="alog -t lvmgs -o"; run_cmd

  snapfile=$snapdir/gsclvmd.snap
  cmd="ps -ef|grep gsclvmd >> $snapfile 2>&1"; string="ps -ef|grep gsclvmd"; run_cmd
  cmd="lssrc -ls gsclvmd >> $snapfile 2>&1"; string="lssrc -ls gsclvmd"; run_cmd
  cmd="lssrc -ls grpsvcs >> $snapfile 2>&1"; string="lssrc -ls grpsvcs"; run_cmd

  # Once per VG
  echo "VGs.\c"
  for vg in $(lsvg)
  do
	  snapfile=$snapdir/$vg.snap
	  if [ $passno = 1 ]; then
		  #lsvg is 1300, lsvg -l is 146 base + 1140 per LV (added below)
		  total_bytes=`expr $total_bytes + 1300 + 146`
		  echo "..\c"
	  else
		  # save output to temp files to use below in "per LV" section
		  tmp1=$snapdir/tmp1.$$
		  tmp2=$snapdir/tmp2.$$
		  cmd="lsvg $vg >> $tmp1 2>&1"; string="lsvg $vg"; run_cmd
		  cat $tmp1 >> $snapfile
		  cmd="lsvg -l $vg >> $tmp2 2>&1"; string="lsvg -l $vg"; run_cmd
		  cat $tmp2 >> $snapfile
    fi

    # Once per LV
    if [ $passno = 1 ]; then
	    #For max performance, assume the VG is small VG, and get # of LVs out of the ODM
	    #if we want better estimation accuracy, we can run lsvg to check the VG type as in phase 2
	    num_lvs=`getlvodm -L $vg|wc -l`

	    #add in 1140 per lv for it's line in lsvg -l (above)
	    #plus 720 bytes for getlvcb -AT
	    total_bytes=`expr $total_bytes + $num_lvs \* 1140 + $num_lvs \* 720`
    else
	    MAXPVS=`cat $tmp1|grep "MAX PVs"|awk {'print $8'}`
	    MAXLVS=`cat $tmp1|grep "MAX LVs"|awk {'print $3'}`
	    if [[ "$MAXPVS" -lt 1024 && "$MAXLVS" -eq 256 ]]; then
		    for lv in $(cat $tmp2|sed -e '1,2d'|awk '{print $1}') 
		    do
			    cmd="getlvcb -AT $lv >> $snapfile 2>&1"; string="getlvcb -AT $lv"; run_cmd 
		    done
	    fi
	    rm -f $tmp1; rm -f $tmp2; 
    fi

  done

  # Check if the system has multipath devices first and add those
  # paths to the list that we don't need to readvgda in the future 
  # and save output to a temporary file to screen out PVs. This is
  # to maximize performance when the system has multipath disks. 
  for disk in $(lspv|grep -e vpath -e hdiskpower|awk {'print $1'})
  do
	  if [[ $disk == vpath* ]]; then
		  odisk=`odmget -q "name=$disk and value like hdisk*" CuAt|grep value|awk -F"[\"/]" '{print $2}'`
	  else
		  odisk=`odmget -q "name=$disk and value like hdisk*" CuAt|grep value|awk -F"[\":]" '{print $2}'`
	  fi
  	  ldisks="$ldisks\n$odisk" 
  done

  # Once per PV, 'readvgda -v7' once, 'readvgda -v3' for the rest.
  currentvgname=""
  echo "PVs.\c"
  lspv|sort -k3|while read disk pvid vgname vgstatus
  do
	  # We don't need to read VGDA for each multipath device
	  echo $ldisks | grep -w "$disk" > /dev/null 2>&1
	  if [ "$?" == 0 ]; then
		  continue
	  fi
	  
	  snapfile=$snapdir/$vgname.snap
	  # Use summary output (-v3) when: we've already run the full readvgda or
	  # there is no imported VG
	  if [ "$vgname" == "$currentvgname" ] || [ "$vgname" = "None" ]; then
		  cmd="readvgda -v3 $disk >> $snapfile 2>&1"; string="readvgda -v3 $disk"; run_cmd
	  else
		  cmd="readvgda -v7 $disk >> $snapfile 2>&1"; string="readvgda -v7 $disk"; run_cmd
		  currentvgname=$vgname
	  fi

  done

	# Collect hdcrypt information if necessary
	# Check that hdcrypt driver is loaded
	if [[ "Available" = $(lsdev -l hdcrypt | awk '{print $2}') ]]; then
		echo "HDCRYPT.\c"
		#Once per hdcrypt snap
		snapfile=$snapdir/hdcrypt.log
		cmd="alog -t hdcrypt -o >> $snapfile 2>&1"; string="alog -t hdcrypt -o"; run_cmd

		snapfile=$snapdir/hdcrypt.snap
		cmd="hdcryptmgr showvg >> $snapfile 2>&1"; string="hdcryptmgr showvg"; run_cmd
		cmd="hdcryptmgr pksshow >> $snapfile 2>&1"; string="hdcryptmgr pksshow"; run_cmd
		cmd="keysvrmgr show >> $snapfile 2>&1"; string="keysvrmgr show"; run_cmd
		for ksvr in $(keysvrmgr show | awk '{if (NR>2){print $1;}}')
		do
			cmd="keysvrmgr show $ksvr >> $snapfile 2>&1"; string="keysvrmgr show $ksvr"; run_cmd
		done

		echo "HDCRYPT_VGs.\c"
		#Once per encryption enabled VG
		for vg in $(hdcryptmgr showvg | awk '$2 ~ /yes/ {print $1}')
		do
			snapfile=$snapdir/hdcrypt.$vg.snap
			cmd="hdcryptmgr showvg $vg >> $snapfile 2>&1"; string="hdcryptmgr showvg $vg"; run_cmd
			cmd="hdcryptmgr showmd -v $vg >> $snapfile 2>&1"; string="hdcryptmgr showmd -v $vg"; run_cmd
			cmd="hdcryptmgr showlv $vg >> $snapfile 2>&1"; string="hdcryptmgr showlv -v $vg"; run_cmd
			#Once per encryption enabled LV
			for lv in $(hdcryptmgr showlv $vg | awk '$2 !~ /not_enabled/ {if(NR>1)print $1}')
			do
				cmd="hdcryptmgr showlv -v $lv >> $snapfile 2>&1"; string="hdcryptmgr showlv -v $lv"; run_cmd
				cmd="hdcryptmgr showmd -v $lv >> $snapfile 2>&1"; string="hdcryptmgr showmd -v $lv"; run_cmd
			done
		done

		echo "HDCRYPT_PVs.\c"
		#Once per PV, read ondisk metadata
		lspv|sort -k3|while read disk pvid vg vgstatus
		do
			snapfile=$snapdir/hdcrypt.$vg.snap
			# Read hdcrypt metadata per disk
			cmd="hdcryptmgr showmd -v $disk >> $snapfile 2>&1"; string="hdcryptmgr showmd -v $disk"; run_cmd
		done

	fi

  echo " done."

}

#Function state_func19
state_func19() 			# function to gather multi CPU trace files 
{
	comp=general
	snapdir=$destdir/$comp
        let iteration=1	
	let remainder=0

	if [ "$passno" = 1 ]
	then 
		echo "Checking space requirement for multicpu  trace files "
	else
		echo "Gathering multicpu trace files\c"
	fi

	#get the list of individual cpu trace files
	file_lst=`trcrpt -t /usr/lib/ras/cpufmt $trcfile`

	#count the number of files
	file_cnt=`echo $file_lst | wc -w `
	
	#get the directory of trace file
	trc_dir=`dirname $trcfile`

	#collect the base trcfile, /etc/trcfmt and output of trcnm
	#if -a flag specified base file will be copied as part of general
	if [ "$doall" != y ]
	then
		string=""
		cmd="cp -p $trcfile $snapdir >/dev/null 2>&1"
		run_cmd
		
		#copy /etc/trcfmt file
                string=""
                cmd="cp -p /etc/trcfmt $snapdir >/dev/null 2>&1"
                run_cmd

                #copy output of trcnm command
                string="trcnm"
                cmd="trcnm > $snapdir/trcnm.out"
                run_cmd

	fi

	if [ $file_cnt != 0 ]
	then 
		for a in $file_lst
		do
			remainder=`expr $iteration % 2`
		        if [ $remainder -eq 0 ]	
			then 
				#Every second field contains name of the file
				#copy individual cpu trace logs
				string=""
				cmd="cp -p $trc_dir/$a $snapdir >/dev/null 2>&1"
				run_cmd
			fi
			let "iteration = iteration + 1"
		done
	fi

	echo "done."


} # End Function state_func19


# Function state_func20
state_func20() {
#            
# 

  comp=wlm
  snapfile=$destdir/$comp/$comp.snap
  snapdir=$destdir/$comp

  string="creation date"
  cmd="date > $snapfile 2>&1"
  run_cmd  

                                                                                
  #copy /etc/wlm files
  string=""
  cmd="cp -pr /etc/wlm/* $snapdir >/dev/null 2>&1"
  run_cmd

	echo "done."

} # End of state_func20

# Function state_func21 - gather platform or scanout dumps.
state_func21 () {
#            
# 

  comp=general
  snapfile=$destdir/$comp/$comp.snap
  snapdir=$destdir/$comp

  if [ "$passno" = 1 ]
  then
  	if [ "$dogen" = n ]
  	then
  	   echo "Checking space requirement for platform/scanout information\c"
	fi
  else
  	echo "Gathering platform/scanout information\c"
  fi

  if [ "$doall" = n -a "$dogen" = n  -a "$dogenoscan" = n ]
  then
  	string="creation date"
  	cmd="date > $snapfile 2>&1"
  	run_cmd  
  fi

  # Get the platform dump directory.
  dir=`odmget -q "attribute = 'fwdump_dir'" SWservAt |\
    awk '$1 == "value" {gsub("\"","",$NF);printf("%s",$NF)}'`

  if [ -z "$dir" ];then
                if [ -f /usr/sbin/platform_dump ];then
                        /usr/sbin/platform_dump -q
                else
                        echo "\n/usr/sbin/platform_dump not found -platform dump may not be installed /supported "
                fi
  else

                string=""

  # Setup the file list.
                if [ -n "$scanfiles" ]
        then    # A list was specified.
        # remove any commas.
                                scanfiles=`echo $scanfiles | sed 's/,/ /g'`
                                for fn in "$scanfiles"
                                do      # for each file.
                                        cmd="cp -p $dir/$fn $snapdir >/dev/null 2>&1"
                                        run_cmd
                                done
                else    # copy all files.
                        cmd="cp -p $dir/* $snapdir >/dev/null 2>&1"
                        run_cmd
                fi
  fi

  # Copy any hypervisor dump files, feature 444784.
  # All dumps of the form /tmp/dumpmmddyy will be gathered.
  if [ -x /usr/sbin/fetchdbg ]
  then	# See if any dumps available and put them in /tmp if so.
	/usr/sbin/fetchdbg -k >/dev/null 2>&1
	if [ $? -eq 0 ]
	then	# data available and in /tmp.
		if [ $passno = 1 ]
		then	string=""
		else	string="Copying hypervisor dumps from /tmp"
		fi
  		lst="ls /tmp/dump[01][0-9][0-3][0-9][0-9][0-9] 2>/dev/null 2>&1"
		for fn in $lst
		do	# for each file
			[[ ! -f $fn ]] && continue
			bname=`basename $fn`
  			cmd="compress < $fn > $snapdir/$bname".Z""
			run_cmd
			string=""
		done
	fi # data available.
  fi # fetchdbg available.

  if [ "$passno" = 2 -o "$dogen" = n ]
  then
	echo "done."
  fi

} # End Function state_func21

# Function state_func22 - scraid
state_func22() {
#
#
  comp=scraid
  snapdir=$destdir/$comp
  snapfile=$destdir/$comp/$comp.snap
  rm -f $snapfile


  if [ "$passno" = 1 ]
  then
        echo "Checking space requirement for $comp information...\c"

  else
        echo "Gathering $comp system information...\c"

  fi

  string="creation date"
  cmd="date >> $snapfile 2>&1"
  run_cmd
  
  string="Operating System Level"
  cmd="oslevel >> $snapfile 2>&1"
  run_cmd
  
  string="available scsi raid adapters"
  for z in $(lsdev -Cr name -Sa|grep scraid)
  do
    cmd="lscfg -vpl $z >> $snapfile 2>&1"
    run_cmd
    unset string
  done

  string="available scsi raid hdisks"
  for k in $(lsdev -Cc disk -t array -SA -r name)
  do
    cmd="scraidmgr -l $k -C >> $snapfile 2>&1"
    run_cmd
    unset string
  done

  string="defined scsi raid hdisks"
  for k in $(lsdev -Cc disk -t array -SD -r name)
  do
    cmd="scraidmgr -l $k -J >> $snapfile 2>&1"
    run_cmd
    unset string
  done

  string="raid logical disks...not formatted output"
  for k in $(lsdev -Cc disk -t array -r name)
  do
    cmd="scraidmgr -l $k -O >> $snapfile 2>&1"
    run_cmd
    unset string
  done

  for i in $(lsdev -Cr name -Sa|grep scraid)
  do
    string="$i: hot spare dirves"
    cmd="scraidmgr -l $i -V >> $snapfile 2>&1"
    run_cmd

    string="$i: failed drives not member of any array"
    cmd="scraidmgr -l $i -W >> $snapfile 2>&1"
    run_cmd

    string="$i: spare drives"
    cmd="scraidmgr -l $i -S >> $snapfile 2>&1"
    run_cmd

    string="$i: physical disks list"
    cmd="scraidmgr -l $i -B >> $snapfile 2>&1"
    run_cmd

    string="$i: physical disks VPD"
    for y in $(scraidmgr -l $i -B|sed "s/::.*//g"|sed  -n  "/[0-9]/p")
    do
      cmd="scraidmgr -P -l $i -y $y >> $snapfile 2>&1"
      run_cmd
      unset string
      cmd='echo "\n" >> $snapfile 2>&1'
      run_cmd
    done

    string="$i: adapter internal errorlog"
    cmd='diag -cd $i -T"adapela" >> $snapfile 2>&1'
    run_cmd
    unset string
    cmd='echo >> $snapfile 2>&1'
    run_cmd

    string="$i: write cache status"
    cmd="scraidmgr -U -l $i >> $snapfile 2>&1"
    run_cmd
    unset string

  done

  echo " done."

} # End of state_func22

# Function state_func23 - wpars
state_func23 () {
#
#


  comp=wpars
  snapdir=$destdir/$comp
  snapfile=$destdir/$comp/$comp.snap
  typeset wparlog=/var/adm/wpars/event.log
  rm -f $snapfile 


  if [ "$passno" = 1 ]
  then

        echo "Checking space requirement for $comp information\c"
  else

        echo "Gathering $comp system information\c"
  fi


  string="lswpar"
  cmd="lswpar -L >> $snapfile 2>&1"
  run_cmd

  for corral in `lswpar -qca name`
  do
     string="$corral"
     cmd="lsfs -u $corral >> $snapfile 2>&1"
     run_cmd
  done

  if [[ -f $wparlog ]]; then
     string="$wparlog"
     cmd="/usr/bin/cat $wparlog >> $snapfile 2>&1"
     run_cmd
  fi

  echo " done."

} # End of state_func23

# Function state_func25 - Gather Flash adapter information
state_func25()
{
	comp=flash
	snapfile=$destdir/$comp/$comp.snap
	snapdir=$destdir/$comp
	mkdir -p $snapdir
	rm $snapfile 2>/dev/null
	touch $snapfile
	collect_flash_data="y"
	if [ "$passno" = 1 ]
	then
		echo "Checking space requirement for $comp information...\c"
	else
		echo "Gathering $comp system information...\c"
	fi

	###############################################
	# Check to see if lsdev cmd exist
	# later check if, flash adapter disk
	# is installed..
	# if, not just return else proceed..
	###############################################

	if [ -x /usr/sbin/lsdev ]
	then
		disk=""
		disk=`/usr/sbin/lsdev -C -c disk -t flashsys -S a | awk '{print $1}'`
		if [ -z "$disk" ]
		then
			string=""
			cmd="echo 'No IBM flash disks available.' >> $snapfile 2>&1"
			run_cmd
			collect_flash_data="n"
		fi
	else
		echo 'No execute permission for "/usr/sbin/lsdev". Skipping "flash" component\c'
		string=""
		cmd="echo 'No execute permission for \"/usr/sbin/lsdev\". Skipping \"flash\" component.' >> $snapfile 2>&1"
		run_cmd
		collect_flash_data="n"
	fi

	###############################################
	# if utility does not exist return error
	###############################################

	if [ ! -f /usr/lpp/diagnostics/bin/rs_cardreport -a $collect_flash_data = "y" ]
	then
		echo '"/usr/lpp/diagnostics/bin/rs_cardreport" utility not found. Skipping "flash" component\c'
		string=""
		cmd="echo '\"/usr/lpp/diagnostics/bin/rs_cardreport\" utility not found. Skipping \"flash\" component.' >> $snapfile 2>&1"
		run_cmd
		collect_flash_data="n"
	fi

	###############################################
	# if no execution permission on utility error
	###############################################

	if [ ! -x /usr/lpp/diagnostics/bin/rs_cardreport -a $collect_flash_data = "y" ]
	then
		echo 'No execute permission for "rs_cardreport" utility. Skipping "flash" component\c'
		string=""
		cmd="echo 'No execute permission for \"rs_cardreport\" utility. Skipping \"flash\" component.' >> $snapfile 2>&1"
		run_cmd
		collect_flash_data="n"
	fi

	###############################################
	# Everything fine, procees things.
	###############################################

	if [ $collect_flash_data = "y" ]
	then
		/usr/sbin/lsdev -C -c disk -t flashsys -S a | awk '{print $1}' | while read flash_disks
		do
			string="/usr/lpp/diagnostics/bin/rs_cardreport /dev/$flash_disks"
			cmd="/usr/lpp/diagnostics/bin/rs_cardreport /dev/$flash_disks >> $snapfile 2>&1"
			run_cmd
		done
	fi
	echo " done."
}


#Function state_func50
state_func50()                  # function to gather HACMP data.
{
  comp=hacmp
  snapdir=$destdir/$comp
  snapfile=$destdir/$comp/$comp.snap

  if [ "$passno" = 1 ]
  then
     initial_setup
  fi

  saveparams=`echo $saveparamlist | sed 's/ /=/g'| sed 's/-/:/g'`
  tdumpf=$snapdir/tmpfile.$$
  rm -rf $tdumpf

  typeset -i fsize=0

  clsnapdir="/usr/es/sbin/cluster/utilities"

  # Make sure HACMP software is installed and clsnap is available 
  if [ -x /usr/es/sbin/cluster/utilities/clsnap ]
  then
     clsnapdir="/usr/es/sbin/cluster/utilities"
  else                                                         
     if [ -e  /usr/es/sbin/cluster/utilities/clsnap ]
     then
	echo "Cannot execute /usr/es/sbin/cluster/utilities/clsnap."
	return
     else
		echo "clsnap not installed on the system."
		return
     fi
  fi
  if [ "$clusterwide" = y ]
  then
        if [ "$passno" = 1 ]
        then
            echo "Checking Space requirement Supressed because of clusterwide operation"
        else
            tdumpf=$destdir/tmpfile.$$
            rm -rf $tdumpf
            $clsnapdir/clsnap  -d $destdir -f $saveparams >$tdumpf
        fi

  else  # Else for clusterwide */
    if [ "$passno" = 1 ]
    then
      if [ "$domflag" = y ]
      then
	$clsnapdir/clsnap -d $snapdir -p 1 -n $nodenames >$tdumpf
      else
	$clsnapdir/clsnap -p 1 -d $snapdir >$tdumpf
      fi

      fsize=`cat $tdumpf |grep "Bytes Required" | awk '{print $1}'`
      total_bytes=`expr $total_bytes + $fsize`
      rm -rf $tdumpf
    else
      if [ "$domflag" = y ]
      then
	  string=""
	  cmd="$clsnapdir/clsnap -d $snapdir -p 2 -n $nodenames >$snapfile "
      else
	  string=""
	  cmd="$clsnapdir/clsnap -p 2 -d $snapdir >$snapfile "
      fi

      run_cmd
    fi
  fi 		# end for if clusterwide 

  echo "done."

} # End Function state_func50 

#LKU section starts here
#LI 80B RAS LKU Changes-defect 933132, Option -U is used for LKU purposes only
#Function state_func98
state_func98()                   # Liveupdate  information.
{ 
  comp=liveupdate
  snapdir=$destdir/$comp

  if [ "$passno" = 1 ]
  then
	echo "Checking space requirement for $comp information...\c" 
  else 
	echo "Gathering $comp system information...\c"
  fi

  #Copy /etc/liveupdate files
  if [ -e "$lvupETCBase" ]
  then
    #Copy the /etc/liveupdate/* files as it is to etc dir
    #Remove potential existing $snapdir/etc to avoid 
    #$snapdir/etc/liveupdate subdir creation via "cp"
    #NOTE:  "snap -U" creates $snapdir/etc and "snap -a"
    #does not and avoids extraneous liveupdate subdir  
    rm -rf $snapdir/etc >/dev/null 2>&1
    string=""
    cmd="cp -p -R $lvupETCBase $snapdir/etc >/dev/null 2>&1"
    run_cmd
  fi

  #Copy /var/adm/ras/liveupdate files
  if [ -e "$lvupLogBase" ]
  then
    #Copy the /var/adm/ras/liveupdate/* filesas it is to liveupdate dir
    #Remove potential existing $snapdir/liveupdate to avoid 
    #$snapdir/liveupdate subdir creation via "cp"
    #NOTE:  "snap -U" creates $snapdir/liveupdate and "snap -a"
    #does not and avoids extraneous liveupdate subdir
    rm -rf $snapdir/liveupdate >/dev/null 2>&1
    string=""
    cmd="cp -p -R $lvupLogBase $snapdir/liveupdate >/dev/null 2>&1"
    run_cmd
  fi

  #Copy the hmcauth.log file 
  if [ -e "$hmcauthlogFile" ]
  then
    string=""
    cmd="cp -p $hmcauthlogFile $snapdir >/dev/null 2>&1"
    run_cmd
  fi

  #Copy the pvcauth.log file 
  if [ -e "$pvcauthlogFile" ]
  then
    string=""
    cmd="cp -p $pvcauthlogFile $snapdir >/dev/null 2>&1"
    run_cmd
  fi

  echo " done."
}
# End Function state_func98

################################################################################
#
# NAME:    state_func97
#
# PURPOSE:
#          Fetch user history and SMIT logs.
#
# INPUT:   Comma seperated usernames whose history is being collected.
#
# ERROR:   Snap exits if some error occurs while collecting the above.
#
################################################################################
# SNAP User shell and SMIT history collection 
# Defect 960212
#Function state_func97
state_func97()
{
  # $comp should match whatever you added to $dirlist
  comp=history
  snapdir=$destdir/$comp
  historyFile=".sh_history"
  smitLogFile="smit.log"

  if [ "$passno" = 1 ]
  then
    echo "Checking space requirement for $comp information... \c" 
  else
    echo "Gathering $comp system information... \c"
  fi

  # Sanity check for userList
  if [[ -z "$userList" ]]; then
    echo "snap: No users specified for history collection"
    exit 1
  fi

  # For every user specified in $userList copy the history and SMIT files
  for thisUser in $userList; do
    # Find home directory for this user
    # No need for user check, as it has already been done
    curUserHome=`cat /etc/passwd | grep $thisUser | cut -d':' -f 6 2>/dev/null`
    if [[ -z "curUserHome" ]]; then
      echo "User ${thisUser}'s home directory not set, continuing... \c"
      continue
    fi
    # If history file exists fetch it
    if [[ -e "$curUserHome/$historyFile" ]]; then
      string=""
      cmd="cp -p $curUserHome/$historyFile $snapdir/$thisUser$historyFile >/dev/null 2>&1"
      run_cmd
    else
      echo "Shell history file not found for $thisUser, continuing... \c"
    fi
    # If SMIT log file exists fetch it
    if [[ -e "$curUserHome/$smitLogFile" ]]; then
      string=""
      cmd="cp -p $curUserHome/$smitLogFile $snapdir/${thisUser}.$smitLogFile >/dev/null 2>&1"
      run_cmd
    else
      echo "SMIT log file not found for $thisUser, continuing... \c"
    fi
  done

  echo " done."
}
# End Function state_func97

#Function state_func121
state_func121()                   # pcixscsi  information.
{ 
  comp=pcixscsi
  snapdir=$destdir/$comp
  snapfile=$destdir/$comp/$comp.snap
  rm -f $snapfile

  if [ "$passno" = 1 ]
  then
        echo "Checking space requirement for $comp information...\c" 
  else 
        echo "Gathering $comp system information...\c"
  fi

  string="creation date"
  cmd="date >> $snapfile 2>&1"
  run_cmd

  string="Operating System Level"
  cmd="oslevel >> $snapfile 2>&1"
  run_cmd

  string="System Software"
  cmd="lslpp -lc | grep 14107802 >> $snapfile 2>&1"
  run_cmd
  unset string
  cmd="lslpp -lc | grep 14106602 >> $snapfile 2>&1"
  run_cmd

  for adap in $(lsdev -C -Fname | grep sisioa)
  do
    string="PCI-X SCSI (RAID) Adapter information for $adap"
    cmd="lsdev -Cl $adap >> $snapfile 2>&1 "
    run_cmd
    unset string
    cmd="echo \"\" >> $snapfile 2>&1"
    run_cmd
    cmd="lsattr -El $adap >> $snapfile 2>&1 "
    run_cmd
    cmd="echo \"\nVPD for $adap\n\" >> $snapfile 2>&1"
    run_cmd
    cmd="lscfg -vl $adap >> $snapfile 2>&1 "
    run_cmd
    #Defect 1029994: Please refer to Note1 in the run_cmd section on how to add an Informational message
    cmd="echo \\\n\"********** RAID Configuration *************\" >> $snapfile 2>&1"
    run_cmd
    cmd="sisraidmgr -L -j1 -l $adap >> $snapfile 2>&1 "
    run_cmd
    for bus in $(lsdev -C -p $adap -Fname)
    do
      cmd="echo \"\nBus information for $bus\n\" >> $snapfile 2>&1"
      run_cmd
      cmd="lsdev -Cl $bus >> $snapfile 2>&1 "
      run_cmd
      cmd="echo \"\" >> $snapfile 2>&1"
      run_cmd
      cmd="lsattr -El $bus >> $snapfile 2>&1 "
      run_cmd
      cmd="echo \"\" >> $snapfile 2>&1"
      run_cmd
      cmd="lscfg -vl $bus >> $snapfile 2>&1 "
      run_cmd
      for device in $(lsdev -C -p $bus -Fname)
      do
        cmd="echo \"\nDevice information for $device (->$bus->$adap)\n\" >> $snapfile 2>&1"
        run_cmd
        cmd="lsdev -Cl $device >> $snapfile 2>&1 "
        run_cmd
        cmd="echo \"\" >> $snapfile 2>&1"
        run_cmd
        cmd="lsattr -El $device >> $snapfile 2>&1 "
        run_cmd
        cmd="echo \"\nVPD for $device\n\" >> $snapfile 2>&1"
        run_cmd
        cmd="lscfg -vl $device >> $snapfile 2>&1 "
        run_cmd
      done
    done
  done

  for adap in $(lsdev -C -Fname | grep sisscsi)
  do
    string="PCI-X SCSI (non-RAID) Adapter information for $adap"
    cmd="lsdev -Cl $adap >> $snapfile 2>&1 "
    run_cmd
    unset string
    cmd="echo \"\" >> $snapfile 2>&1"
    run_cmd
    cmd="lsattr -El $adap >> $snapfile 2>&1 "
    run_cmd
    cmd="echo \"\nVPD for $adap\n\" >> $snapfile 2>&1"
    run_cmd
    cmd="lscfg -vl $adap >> $snapfile 2>&1 "
    run_cmd
    for bus in $(lsdev -C -p $adap -Fname)
    do
      cmd="echo \"\nBus information for $bus\n\" >> $snapfile 2>&1"
      run_cmd
      cmd="lsdev -Cl $bus >> $snapfile 2>&1 "
      run_cmd
      cmd="echo \"\" >> $snapfile 2>&1"
      run_cmd
      cmd="lsattr -El $bus >> $snapfile 2>&1 "
      run_cmd
      cmd="echo \"\" >> $snapfile 2>&1"
      run_cmd
      cmd="lscfg -vl $bus >> $snapfile 2>&1 "
      run_cmd
      for device in $(lsdev -C -p $bus -Fname)
      do
        cmd="echo \"\nDevice information for $device (->$bus->$adap)\n\" >> $snapfile 2>&1"
        run_cmd
        cmd="lsdev -Cl $device >> $snapfile 2>&1 "
        run_cmd
        cmd="echo \"\" >> $snapfile 2>&1"
        run_cmd
        cmd="lsattr -El $device >> $snapfile 2>&1 "
        run_cmd
        cmd="echo \"\nVPD for $device\n\" >> $snapfile 2>&1"
        run_cmd
        cmd="lscfg -vl $device >> $snapfile 2>&1 "
        run_cmd
      done
    done
  done

  echo " done."
}
# End Function state_func121

#Function state_func122
state_func122()                   # sissas  information.
{ 
  comp=sissas
  snapdir=$destdir/$comp
  snapfile=$destdir/$comp/$comp.snap
  rm -f $snapfile

  if [ "$passno" = 1 ]
  then
        echo "Checking space requirement for $comp information...\c" 
  else 
        echo "Gathering $comp system information...\c"
  fi

  string="creation date"
  cmd="date >> $snapfile 2>&1"
  run_cmd

  string="Operating System Level"
  cmd="oslevel >> $snapfile 2>&1"
  run_cmd

  string="System Software"
  cmd="lslpp -lc | grep 1410bd02 >> $snapfile 2>&1"
  run_cmd
  unset string

  for adap in $(lsdev -C -Fname | grep sissas)
  do
    string="SISSAS Adapter information for $adap"
    cmd="lsdev -Cl $adap >> $snapfile 2>&1 "
    run_cmd
    unset string
    cmd="echo \"\" >> $snapfile 2>&1"
    run_cmd
    cmd="lsattr -El $adap >> $snapfile 2>&1 "
    run_cmd
    cmd="echo \"\nVPD for $adap\n\" >> $snapfile 2>&1"
    run_cmd
    cmd="lscfg -vl $adap >> $snapfile 2>&1 "
    run_cmd
    #Defect 1029994: Please refer to Note1 in the run_cmd section on how to add an Informational message
    cmd="echo \\\n\"********** RAID Configuration *************\" >> $snapfile 2>&1"
    run_cmd
    cmd="sissasraidmgr -L -j1 -l $adap >> $snapfile 2>&1 "
    run_cmd
    #Defect 1029994: Please refer to Note1 in the run_cmd section on how to add an Informational message
    cmd="echo \\\n\"********** Multi-path Summary *************\" >> $snapfile 2>&1"
    run_cmd
    cmd="sissasraidmgr -Tl $adap -j3 >> $snapfile 2>&1 "
    run_cmd
    #Defect 1029994: Please refer to Note1 in the run_cmd section on how to add an Informational message
    cmd="echo \\\n\"********** Multi-path Full Details *************\" >> $snapfile 2>&1"
    run_cmd
    cmd="sissasraidmgr -Tl $adap -j3 -o1 >> $snapfile 2>&1 "
    run_cmd
    for bus in $(lsdev -C -p $adap -Fname)
    do
      cmd="echo \"\nBus information for $bus\n\" >> $snapfile 2>&1"
      run_cmd
      cmd="lsdev -Cl $bus >> $snapfile 2>&1 "
      run_cmd
      cmd="echo \"\" >> $snapfile 2>&1"
      run_cmd
      cmd="lsattr -El $bus >> $snapfile 2>&1 "
      run_cmd
      cmd="echo \"\" >> $snapfile 2>&1"
      run_cmd
      cmd="lscfg -vl $bus >> $snapfile 2>&1 "
      run_cmd
      for device in $(lsdev -C -p $bus -Fname)
      do
        cmd="echo \"\nDevice information for $device (->$bus->$adap)\n\" >> $snapfile 2>&1"
        run_cmd
        cmd="lsdev -Cl $device >> $snapfile 2>&1 "
        run_cmd
        cmd="echo \"\" >> $snapfile 2>&1"
        run_cmd
        cmd="lsattr -El $device >> $snapfile 2>&1 "
        run_cmd
        cmd="echo \"\nVPD for $device\n\" >> $snapfile 2>&1"
        run_cmd
        cmd="lscfg -vl $device >> $snapfile 2>&1 "
        run_cmd
      done
    done
  done

  echo " done."
}
# End Function state_func122

# Function state_func99
state_func99()
{
    # setup each script to execute as a component
    for script in $scripts
    do
      scriptname=`echo $script | awk -F '' '{print $1}' | sed 's/\"//g'`
      scriptcmd=`echo $script | sed 's// /g' | sed 's/\"//g'`
      initial_setup
      snap_script

    done

} # End of state_func99


# Function state_func123 for InfiniBand (doIB)
state_func123() 
{
#
#
  comp=IB
  snapfile=$destdir/$comp/$comp.snap
  snapdir=$destdir/$comp
  # create the IB directory:
  mkdir -p $snapdir 
  rm $snapfile 2>/dev/null

  if [ "$passno" = 1 ]
  then
        echo "Checking space requirement for $comp information\c"
  else
        echo "Gathering $comp system information\c"
  fi

  string="creation date"
  cmd="date >> $snapfile 2>&1"
  run_cmd

# Get all streams modules what/sum information

  for i in if_ib gxibdd icmdd rds  
   do
        string="what /usr/lib/drivers/$i"
        cmd="what /usr/lib/drivers/$i >> $snapfile 2>&1"
        run_cmd

        string="sum /usr/lib/drivers/$i"
        cmd="sum /usr/lib/drivers/$i >> $snapfile 2>&1"
        run_cmd
   done


  for i in tsibdd64 mxibdd64 
   do
        string="what /usr/lib/drivers/pci/$i"
        cmd="what /usr/lib/drivers/pci/$i >> $snapfile 2>&1"
        run_cmd

        string="sum /usr/lib/drivers/pci/$i"
        cmd="sum /usr/lib/drivers/pci/$i >> $snapfile 2>&1"
        run_cmd
   done

  string=" netstat -Cnt"
  cmd="$string  >> $snapfile 2>&1"
  run_cmd

  # Save the ndpd-router configuration file file 
  x=`lssrc -s ndpd-router | grep active`

  if [ "$x" != "" ]
     then
          # copy the ndpd-router config file into the snapdir.
          string="ndpd-router is running"
          cmd=""
          run_cmd

          if [ -f "/etc/gateway6" ]
          then
          string="cp /etc/gateway6 to $snapdir"
          cmd="cp /etc/gateway6 $snapdir  >> $snapfile 2>&1"
          run_cmd
          fi
   fi

   x=`lssrc -s ndpd-host | grep active `

   if [ "$x" != "" ]
      then
          string="ndpd-host is running"
          cmd=""
          run_cmd
   fi

  # Retrieving the O.S level
  string="O.S  level"
  cmd=" what /unix | grep _kdb_  >> $snapfile 2>&1"
  run_cmd

  # Retrieving fileset levels

  string="lslpp -h devices.common.IBM.ib.rte"
  cmd="$string  >> $snapfile 2>&1"
  run_cmd

  string="lslpp -h devices.chrp.IBM.lhca.rte"
  cmd="$string  >> $snapfile 2>&1"
  run_cmd

  string="lslpp -h devices.pciex.b3154a63.rte"
  cmd="$string  >> $snapfile 2>&1"
  run_cmd

  string="emgr -l"
  cmd="$string  >> $snapfile 2>&1"
  run_cmd 

  string="uname -M"
  cmd="$string  >> $snapfile 2>&1"
  run_cmd

  string="lsmcode"
  cmd="$string  >> $snapfile 2>&1"
  run_cmd


  string=" netstat -i"
  cmd="$string  >> $snapfile 2>&1"
  run_cmd

  string=" netstat -D"
  cmd="$string  >> $snapfile 2>&1"
  run_cmd

  string="lsdev -Cc if"
  cmd="$string  >> $snapfile 2>&1"
  run_cmd

  string="lsdev -Cc adapter"
  cmd="$string  >> $snapfile 2>&1"
  run_cmd

  string="no -Fa"
  cmd="$string  >> $snapfile 2>&1"
  run_cmd


  # Retrieving VIPA information.

  lsdev -Cc if | grep vi0 >/dev/null
  if [ $? = 0 ]
  then
     string="lsattr -El vi0"
     cmd="$string  >> $snapfile 2>&1"
     run_cmd 
  fi

  # Retrieving the multilink interface information.
  lsdev -Cc if | grep ml0 >/dev/null

  if [ $? = 0 ]
  then
     string="lsattr -El ml0"
     cmd="$string  >> $snapfile 2>&1"
     run_cmd
  fi

  # Retrieving the ibstat -s ibX information.

  INTERFACES=`lsdev -Cc if | grep ib | awk ' { print $1 }' `
  for x in $INTERFACES; do
    echo "\nInformation for $x" >>$snapfile
    string="ibstat -s $x"
    cmd="$string  >> $snapfile 2>&1"
    run_cmd
  done

  # check the ifconfig ibX output of all the interfaces. 
  # ifconfig -a will not decode the right information.

  for x in $INTERFACES; do
    string="ifconfig  $x"
    cmd="$string  >> $snapfile 2>&1"
    run_cmd
  done

  # check the ODM configuration for all the InfiniBand interfaces.
  for x in $INTERFACES; do
    string="lsattr -El $x"
    cmd="$string  >> $snapfile 2>&1"
    run_cmd
  done

  # check the ODM configuration for ICM.
  string="lsattr -El icm"
  cmd="$string  >> $snapfile 2>&1"
  run_cmd

 
  # Retrieving general InfiniBand information with ibstat -v

  string="ibstat -v"
  cmd="$string  >> $snapfile 2>&1"
  run_cmd

  string="Retrieving InfiniBand error logs"
  IBLOGS="GXIB_INFO,IB_IF_CONFIGURATION,IB_IF_ERROR,IB_IF_TEMP_ERROR,IFIB_INFO_ERRLOG,IFIB_PERM_ERRLOG"
  cmd=" errpt -a -J $IBLOGS >> $snapfile 2>&1"
  run_cmd

  # Retrieving trace information 
  string="Component trace location: $snapdir/internal_traces"
  cmd=""
  run_cmd
 
  ctctrl -q -c icm 2>/dev/null 1>/dev/null
  if [ $? = 0 ]
  then
    # Show the component trace levels and buffer size.
    string="ctctrl -t network_ib -r -q"
    cmd="$string  >> $snapfile 2>&1"
    run_cmd

    # Retrieve internal trace buffer binaries for IB.
    string=" ctctrl -t network_ib -r -D -d  $snapdir/internal_traces"
    cmd="$string  >> $snapfile 2>&1"
    run_cmd
  fi          

  echo "done."

}

# End Function state_func123 
# Function state_func26
state_func26 () {
    comp=perf
    snapfile=$destdir/$comp/$comp.snap
    snapdir=$destdir/$comp

    if [ ! -d "$snapdir" ]
    then
       mkdir -p $snapdir
    fi

    if [ "$passno" = 1 ]
    then
       echo "Checking space requirement for $comp information\c"
    else
          echo "Gathering $comp system information\c"
    fi

    string="creation date"
    cmd="date > $snapfile 2>&1"
    run_cmd
    topasrec_tmp=`grep topasrec /etc/inittab | grep -v "^:" `
          if [ "$topasrec_tmp" != "" ]; then
                  topasrec_dir=`echo $topasrec_tmp | awk '{
                          for (i=0; i<NF; i++)
                          {
                                  if ($i == "-o" ) {
                                  print $(i+1);
                                  break;
                                  }
                          }
                  }'  `
                  cmd="cp -p $topasrec_dir/*.topas $snapdir >/dev/null 2>&1"
                  run_cmd
           else  # topasrec not found in /etc/inittab
           cmd="cp -p /var/perf/daily/*.topas $snapdir >/dev/null 2>&1"
           run_cmd
           fi
 } #End Function state_func26

# Function snap_script
snap_script()
{

    comp=$scriptname
    snapdir=$destdir/$comp
    snapfile=$destdir/$comp/$comp.snap
    cmd=$scriptcmd

    scripterr="The script $scriptname is not executable in $scriptrepos"

    echo "Calling $cmd in pass $passno" >> $destdir/script.log

    if [ "$passno" = 1 ]
    then
	initial_setup
	echo "Checking Space requirement for $scriptname"
    else
	echo "Gathering $comp data"
    fi
    
    # check if the script exists
    if [ -x $scriptrepos/$comp ]
    then
	
        # export the environment variables to be picked up by
        # script
	export SNAPDIR=$destdir/$comp
        export PASSNO=$passno
	export SCRIPTSIZE=$destdir/$comp/$comp.size
	export SCRIPTSIZEEST=$SCRIPTSIZE
	export SCRIPTLOG=$destdir/$comp/$comp.log

        # execute the script
        $scriptrepos/$scriptcmd > $destdir/$comp/$comp.out 2>$destdir/$comp/$comp.err

	if [ "$?" = 0 ]
	then
	    if [ "$passno" = 1 ]
	    then
		if [ -r $SCRIPTSIZE ]
		then
		    size=`cat $SCRIPTSIZE`
		    if [ ! -n "$size" ]
		    then
			echo "attention:$cmd did not return a size estimate" >> $destdir/script.log 
			size=0
		    fi
		else
		    echo "attention:$cmd did not create size estimation file" >> $destdir/script.log 
		    size=0
		fi
		
		total_bytes=`expr $total_bytes + $size`
	    fi
	else

	    echo "error:$cmd returned error $?" >> $destdir/script.log
	fi
    else # File was not executable.	

	echo "error:$scripterr" >> $destdir/script.log
	echo $scripterr

	rm -rf $destdir/$comp
    fi

} # End of snap_script

#Function: execute_debug_command()
#This function execute the debug command registered by an external software.
#input: Product name for which the debug command needs to be run.
#Output: It invokes the the debug command with appropriate timeout [-M]
#Also appends the product name to SNAPDEBUGENV variable if the debug command was successfully invoked.
#Please note, this will not look for the return code for the debug command

execute_debug_command()
{
	product_exec="$1"
	command_exec=""		#Command to execute.
	comp="products"

	prdt_wo_space=`echo $product_exec | tr -s " " | tr -s " " "_"`
	export SNAPDIR=$destdir/$comp/$prdt_wo_space
	export SCRIPTSIZE=$SNAPDIR/debugdata.size
	export SCRIPTLOG=$SNAPDIR/snap.log
	export PASSNO=$passno

	echo $SNAPDEBUGDATA | grep "$1:" >/dev/null 2>&1
	if [ "$?" = 0 ]
	then
		#Product already processed. Simply return
		return
	fi

	echo $SNAPDEBUGDATA | grep ":$1" >/dev/null 2>&1
	if [ "$?" = 0 ]
	then
		#Product already processed. Simply return
		return
	fi

	echo $SKIP_PRODUCTS | grep ":$1"  >/dev/null 2>&1
	if [ "$?" = 0 ]
	then
		#Product was already processed. There are some issue with debug command. Skip it.
		return
	fi

	#Get all the ODM entries for product.
	odmget -q "product_name='$1'" snap_config > $zrun_exec_file 2>/dev/null

	#Pick the last entry from ODM
	cat $zrun_exec_file |while read line
	do
		echo $line | grep "command_path ="  >/dev/null 2>&1
		if [ "$?" = 0 ]
		then
			command_exec=`echo $line | cut -d= -f2- | sed 's/^[ 	]*"//g' | sed 's/"[ 	]*$//'`
			continue
		fi
	done

	
	if [ "$passno" = 1 ]
	then
		mkdir -p "$SNAPDIR" > /dev/null 2>&1
		rm -f "$SCRIPTLOG" > /dev/null 2>&1
	fi

	#Validate the command

	echo $command_exec | grep "^/usr/lib/ras/snapscripts" >/dev/null 2>&1
	if [ "$?" != 0 ]
	then
		echo "snap: passno $passno: Debug command for the product[$product_exec] not in /usr/lib/ras/snapscripts dir" >>$SCRIPTLOG
		echo "Debug command is : $command_exec" >>$SCRIPTLOG
		SKIP_PRODUCTS=$SKIP_PRODUCTS:"$product_exec"
		return
	fi

	cmd_wo_options=`echo $command_exec | awk -F\  '{print $1}'`
	if [ ! -e "$cmd_wo_options" ]
	then
		echo "snap: passno $passno: Debug command for the product[$product_exec] doesn't exists." >>$SCRIPTLOG
		SKIP_PRODUCTS=$SKIP_PRODUCTS:"$product_exec"
		return
	fi
	
	if [ ! -x "$cmd_wo_options" ]
	then
		echo "snap: passno $passno: Debug command for the product[$product_exec] doesn't have execute permission." >>$SCRIPTLOG
		SKIP_PRODUCTS=$SKIP_PRODUCTS:"$product_exec"
		return
	fi

	echo $command_exec | grep "|" >/dev/null 2>&1
	if [ "$?" = 0 ]
	then
		echo "snap: passno $passno: Debug command contains special char for the product[$product_exec].Skipping it" >>$SCRIPTLOG
		SKIP_PRODUCTS=$SKIP_PRODUCTS:"$product_exec"
		return
	fi

	echo $command_exec | grep "\`" >/dev/null 2>&1
	if [ "$?" = 0 ]
	then
		echo "snap: passno $passno: Debug command contains special char for the product[$product_exec].Skipping it" >>$SCRIPTLOG
		SKIP_PRODUCTS=$SKIP_PRODUCTS:"$product_exec"
		return
	fi

	echo $command_exec | grep "<" >/dev/null 2>&1
	if [ "$?" = 0 ]
	then
		echo "snap: passno $passno: Debug command contains special char for the product[$product_exec].Skipping it" >>$SCRIPTLOG
		SKIP_PRODUCTS=$SKIP_PRODUCTS:"$product_exec"
		return
	fi

	#Execute the command with timeout.
	if [ "$passno" = 1 ]
	then
		echo "snap : Checking space requirement for product[$product_exec]"
	elif [ "$passno" = 2 ]
	then
		echo "snap : Gathering debug data for product[$product_exec]"
	fi

	export ODMDIR="$Z_OLD_ODMDIR"

	eval $command_exec >$SNAPDIR/command.out 2>$SNAPDIR/command.err &
	command_pid=$!

	export ODMDIR="$Z_ODMDIR"

	( sleep $cmdtimeout && kill -9 `ps -o pid -T $command_pid | grep -v PID | tr -s '\n' '|' | awk -F"|" '{
                                        for(i=NF-1;i>0;i--)
                                        {
                                                printf("%d ",$i);
                                        }
                                }'` >/dev/null 2>&1 ) >/dev/null 2>&1 &
	wait $command_pid >/dev/null 2>&1
	if [ "$?" = 137 ]
	then
		echo "snap: passno $passno: Debug command for the product[$product_exec] was probably
		      killed since it took more than max timeout[$cmdtimeout secs]" >>$SCRIPTLOG
	fi
	if [ "$passno" = 1 ]
	then

		if [ -r $SCRIPTSIZE ]
		then
			size=`cat $SCRIPTSIZE`
			if [ ! -n "$size" ]
			then
				echo "attention:$command_exec did not return a size estimate" >> $SCRIPTLOG
				size=0
			fi
		else
			echo "attention:$command_exec did not create size estimation file" >> $SCRIPTLOG
			size=0
		fi

		total_bytes=`expr $total_bytes + $size`
	fi

	if [ -n "$SNAPDEBUGDATA" ]
	then
		SNAPDEBUGDATA=$SNAPDEBUGDATA:"$product_exec"
	else
		SNAPDEBUGDATA="$product_exec"
	fi
			
} #End of execute_debug_command

#Function execute_debug_class
#This function will process all the products belonging to a class.
#Input : Class name
#Ouput: Will call execute_debug_command for each product found under the class.

execute_debug_class()
{
	foundclass=n
	echo $processed_class | grep ":$1"  >/dev/null 2>&1
	if [ "$?" = 0 ]
	then
		#This class is already processed. Simply return.
		return
	fi

	odmget -q "class='$1'" snap_config > $zrun_exec_class_file 2>/dev/null

	cat $zrun_exec_class_file |while read line
	do
		echo $line | grep "product_name =" >/dev/null 2>&1
		if [ "$?" = 0 ]
		then
			product_edc=`echo $line | cut -d= -f2- | sed 's/^[ 	]*"//g' | sed 's/"[ 	]*$//'`
			execute_debug_command "$product_edc"
			foundclass=y
		fi
	done

	if [ $foundclass = n ]
	then
		echo "No products found under the class: $1." >> $destdir/products/class.log
	fi

	processed_class=$processed_class:$1

} #End of execute_debug_class

#Function : zderegister()
#Function is called to delete the ODM enteries and debug command from the repository
#input: None. Reads inputs from zdel_temp_file file.
#Ouput: None

z_deregister()
{
	if [ "$zdel" != "y" -a "$zadd" != "y" ]
	then
		#This function shouldn't have been called. Return sliently
		return
	fi

	if [ -e $zdel_temp_file ]
	then
		product_z=`grep "product_name=" $zdel_temp_file | awk -F"=" '{print $2}'`
		if [ -n $product_z ]
		then
			odmget -q "product_name='$product_z'" snap_config  >$zget_temp_file 2>/dev/null
			
			grep "$product_z" $zget_temp_file >/dev/null 2>&1
			if [ "$?" = 0 ]
			then
				if [ "$zdel" = "y" ]
				then
					echo "Deleting the following entries from the ODM:"
				elif [ "$zadd" = "y" ]
				then
					echo "Deleting the existing duplicate entries before adding the new entry:"
				fi
				cat $zget_temp_file
				odmdelete -o snap_config -q "product_name='$product_z'"  >/dev/null 2>&1
				echo "snap: $product_z information deleted from ODM"

				cat $zget_temp_file | while read line
				do
					echo $line | grep "command_path ="  >/dev/null 2>&1
					if [ "$?" = 0 ]
					then
						#Remove "" from the value field in odm output
						cmdpath_z=`echo $line | awk -F"=" '{print $2}' | sed 's/^[ 	]*//'|  sed 's/^[\"]*//' | sed -e 's/"$//g'`
						cmdpath_z=`echo $cmdpath_z|awk '{print $1}'`  #Strip the options

						echo $cmdpath_z | grep "^/usr/lib/ras/snapscripts" >/dev/null 2>&1
						if [ "$?" != 0 ]
						then
							#Don't delete the binary, since its not in repository.
							continue
						fi
						if [ ! -x $cmdpath_z ]
						then
							continue
						fi
						#Delete only if its a file. Purposefully not deleting dir structure.
						if [ -f $cmdpath_z ]
						then
							rm -f "$cmdpath_z" >/dev/null 2>&1
							tmp_product_z=`echo $product_z| tr -s " " | tr " "  "_"`
							#Delete the dir if it doesn't contain anything else
							rmdir /usr/lib/ras/snapscripts/bin/$tmp_product_z >/dev/null 2>&1
							continue
						fi
						if [ "$zdel" = y ]
						then
							echo "snap: Warning - $cmdpath_z was not deleted."
						fi
					fi

				done
			else
				if [ "$zdel" = y ]
				then
					echo "snap: No match found for deletion"
				fi
			fi
		else
			echo "snap: Error - Internal file corrupted for -z DELETE"
			z_remove_tmp	
			exit 1
		fi
	else
		echo "snap: Error - Internal file missing for -z DELETE"
		z_remove_tmp
		exit 2
	fi
} #End of z_deregister

#Function: z_register()
#Will be called for -z ADD. 
#Input : None
#Output: Nonee
#Reads zadd_temp_file, validates it and adds to ODM[snap_config]
#

z_register()
{
	if [ "$zadd" != "y" ]
	then
		#This function shouldn't have been called. Return sliently
		return
	fi

	if [ -e $zadd_temp_file ]
	then
		product_rz=`grep "product_name=" $zadd_temp_file |awk -F"=" '{print $2}'`
		cmdpath_rz=`grep "command_path=" $zadd_temp_file | awk -F"=" {'print $2}`
		class_rz=`grep "class=" $zadd_temp_file | awk -F"=" '{print $2}'`
		tmp_product_rz=`echo $product_rz| tr -s " " | tr " "  "_"`

		cmdpath_rz=`echo $cmdpath_rz|awk '{print $1}'`   #Strip off the options
		echo $cmdpath_rz | grep -E "^/" >/dev/null 2>&1
		if [ $? != 0 ]
		then
			echo "snap: Error: path name of executable has to be absolute"
			z_remove_tmp
			exit 1
		fi

	        cmd_wo_options=`echo $cmdpath_rz | awk -F\  '{print $1}'`
	        if [ ! -e "$cmd_wo_options" ]
	        then
	                echo "snap: Debug command for the product[$product_rz] doesn't exists."
			z_remove_tmp
			exit 1
	        fi

	        if [ ! -x "$cmd_wo_options" ]
	        then
	                echo "snap: Debug command for the product[$product_rz] doesn't have execute permission." 
			z_remove_tmp
			exit 1
	        fi
	        echo $cmdpath_rz | grep "|" >/dev/null 2>&1
	        if [ "$?" = 0 ]
	        then
	                echo "snap: Debug command contains special char for the product[$product_rz]."
			z_remove_tmp
			exit 1
	        fi

	        echo $cmdpath_rz | grep "\`" >/dev/null 2>&1
	        if [ "$?" = 0 ]
	        then
	                echo "snap: Debug command contains special char for the product[$product_rz]."
			z_remove_tmp
			exit 1
	        fi

	        echo $cmdpath_rz | grep "<" >/dev/null 2>&1
	        if [ "$?" = 0 ]
	        then
	                echo "snap: Debug command contains special char for the product[$product_rz]."
			z_remove_tmp
			exit 1
	        fi

		echo "product_name=$product_rz" > $zdel_temp_file
		z_deregister		#Delete the existing entries if any.

		mkdir -p "/usr/lib/ras/snapscripts/bin/$tmp_product_rz"


		cp $cmdpath_rz "/usr/lib/ras/snapscripts/bin/$tmp_product_rz"
		if [ "$?" != 0 ]
		then
			echo "snap: Error - The command [cp $cmdpath_rz /usr/lib/ras/snapscripts/bin/$tmp_product_rz] failed. Exiting..."
			rmdir /usr/lib/ras/snapscripts/bin/$tmp_product_rz >/dev/null 2>&1
			z_remove_tmp
			exit 2
		fi


		#Rewrite the ODM file with correct command path
		cmdpath_rz=`grep "command_path=" $zadd_temp_file | awk -F"=" '{print $2}'`
		cmd_rz=${cmdpath_rz##*/}
		echo "snap_config:" >$zadd_temp_file
		echo "product_name=$product_rz" >>$zadd_temp_file
		echo "command_path=/usr/lib/ras/snapscripts/bin/$tmp_product_rz/$cmd_rz" >>$zadd_temp_file
		echo "class=$class_rz" >>$zadd_temp_file

		string=""
		cmd="odmadd  $zadd_temp_file >/dev/null 2>&1"
		run_cmd
		echo "snap: $product_rz information added to ODM"
		
	else
		echo "snap: Error - Internal file missing for -z ADD. Exiting.."
		z_remove_tmp
		exit 3
	fi
		
		
		
return
} #End of z_register


#Function: state_func24
#This processs the -z flag.

state_func24()
{
	#Reset the values for the next pass.
	export SNAPDEBUGDATA=""
	processed_class=""
	Z_OLD_ODMDIR="$ODMDIR"
	export ODMDIR="$Z_ODMDIR"
	odmget snap_config >/dev/null 2>&1
	if [ $? != 0 ]
	then
		echo "snap: Error snap_config data does not exist, contact IBM for support"
		exit 1
	fi
	#If -z ADD/DELETE is being used
	if [ "$zadd" = "y" -o "$zdel" = "y" ]
	then
		#If ADD or DELETE is being used, we shouldn't be invoked again in passno 1.
		#Only data collection part is invoked for passno 1. Here there is no data collection.
		if [ $passno != 2 ]
		then
			echo "snap: Internal error while processing -z flag"
			z_remove_tmp
			exit 24
		fi
		# Check the permission
		/usr/bin/ckauth aix.ras.snap
		if [ $? != 0 ]
		then
			echo "snap: Only users with aix.ras.snap authorization can run snap -z ADD/DELETE"
			exit 24
		fi
		if [ "$zadd" = "y" ]
		then
			z_register
		else
			z_deregister
		fi

	elif [ "$zrun" = y -a "$zall" != "y" ] #Collection is needed only for some products. Use the zrun_temp_file
	then
		cat $zrun_temp_file | while read line
		do
			echo $line | grep "product_name=" >/dev/null 2>&1
			if [ "$?" = 0 ]
			then
				product_24=`echo $line | cut -d= -f2- | sed 's/^[ 	]*"//g' | sed 's/"[ 	]*$//'`
				execute_debug_command "$product_24"
				continue
			fi

			echo $line | grep "class=" >/dev/null 2>&1
			if [ "$?" = 0 ]
			then
				class_24=`echo $line | cut -d= -f2- | sed 's/^[ 	]*"//g' | sed 's/"[ 	]*$//'`
				execute_debug_class "$class_24"
				continue
			fi	
		
			#Should not reach here.
			echo "snap: Internal error while processing -z. Skipping the corrupted entry"
		done

	elif [ "$zall" = "y" ]
	then
		#Collect data for all the registered products
		odmget snap_config > $zall_temp_file 2>/dev/null
		cat $zall_temp_file | while read line
		do
			echo $line | grep "product_name =" >/dev/null 2>&1
			if [ "$?" = 0 ]
			then
				product_24=`echo $line | awk -F"=" '{print $2}' | sed 's/^[ 	]*"//g' | sed 's/"[ 	]*$//'`
				execute_debug_command "$product_24"
				continue
			fi
		done
	fi

	export ODMDIR="$Z_OLD_ODMDIR"

} #End of function state_func24
		
		

	

#Function: z_remove_tmp
#Remove all tmp files used by -z flag.
z_remove_tmp() {
	rm -f $zadd_temp_file $zdel_temp_file $zrun_temp_file $zget_temp_file $zall_temp_file $zrun_exec_file $zrun_exec_class_file
}

#Function: z_validate
#This function will process the parameters for -z flag.
#The process flags will be placed in appropriate tmp files for later usage.
#
#Input: Arguments for -z along with Keywords.
#Output: Processed output in appropriate tmp files 
#
z_validate() {
	let z_count=0;
	let z_total=0;

	z_product_name=""
	z_class_name=""
	z_command_path=""

	if [ "$1" = "ADD" ]
	then
		#zadd_temp_file will be filled with the data that needs to be added to ODM.
	
		while [ "$z_count" -lt 3 ]
		do
			#Parameters should be in param=value format.
			z_param_name=`echo $2 | awk -F"="  '{print $1}' | sed 's/^[ 	]*//'| sed 's/[ 	]*$//' `
			z_param_value=`echo $2 | awk -F"="  '{print $2}' | sed 's/^[ 	]*//'| sed 's/[ 	]*$//'`
			let z_count=$z_count+1

			case "$z_param_name" in
				product_name)
						z_product_name="$z_param_value"
						;;
				class)
						z_class_name="$z_param_value"
						;;
				command_path)
						z_command_path="$z_param_value"

						echo $z_command_path | grep -E "^/" >/dev/null 2>&1
						if [ $? != 0 ]
						then
							echo "snap: command path in -z flag should be absolute"
							z_remove_tmp
							exit 4
						fi
						;;
				*)
						echo "snap: Invalid member[$z_param_name] with -z ADD option"
						usage
						z_remove_tmp
						exit 101
						;;
			esac
			
			shift	#Shift to process the next parameter.
		done

		if [[ -z $z_product_name ]] || [[ -z $z_class_name ]] || [[ -z $z_command_path ]]
		then
			echo "snap: Some member missing in -z ADD"
			usage
			z_remove_tmp
			exit 101
		fi
		echo "snap_config:" > $zadd_temp_file
		echo "product_name=$z_product_name" >> $zadd_temp_file
		echo "class=$z_class_name" >>$zadd_temp_file
		echo "command_path=$z_command_path" >>$zadd_temp_file

	elif [ "$1" = "DELETE" ]
	then
		z_param_name=`echo $2 | awk -F"="  '{print $1}' | sed 's/^[ 	]*//'| sed 's/[ 	]*$//' `
		z_param_value=`echo $2 | awk -F"="  '{print $2}' | sed 's/^[ 	]*//'| sed 's/[ 	]*$//'`

		case "$z_param_name" in
			product_name)
					echo "product_name=$z_param_value" > $zdel_temp_file
					;;
			*)
					echo "snap: Error - Only product_name can be used with -z DELETE"
					usage
					z_remove_tmp
					exit 101
					;;
		esac
	else
		echo $1 | tr -s ',' '\n' | while read line
		do
			z_param_name=`echo $line | awk -F"="  '{print $1}' | sed 's/^[ 	]*//'| sed 's/[ 	]*$//' `
			z_param_value=`echo $line | awk -F"="  '{print $2}' | sed 's/^[ 	]*//'| sed 's/[ 	]*$//'`

			case "$z_param_name" in
				product_name)
						echo "product_name=$z_param_value" >> $zrun_temp_file
						;;
				class)
						echo "class=$z_param_value" >> $zrun_temp_file
						;;
				ALL)
						zall=y
						;;
				*)
						echo "snap: Error - Invalid options to -z flag."
						usage
						z_remove_tmp
						exit 101
						;;
				esac
		done
	fi
}


#Function: z_parameter
#This function will analyse the parameters passed to -z flag. 
#Input: All the parameters passed to -z. Max 4. So Better call this
#with all the four parameters after -z flag. This function will process 
#only needed parameters based on the flag usage for -z [ADD/DEL/Run]
#
#Output: zshift will contain the number of parameters processed.
#It will call z_validate for validation of parameters.
#
z_parameter() {

	if [ "$zadd" = "y" -o "$zdel" = "y" -o "$zrun" = "y" ]
	then
		echo "snap: Error -z flag can be used only once."
		usage
		z_remove_tmp
		exit 101
	fi
	case "$1" in
		ADD)	
			zadd=y
			zshift=4	#Four arguments will be processed. ADD followed by three product registeration details
			z_validate ADD "$2" "$3" "$4"
			;;

		DELETE)	
			zdel=y
			zshift=2
			z_validate DELETE "$2"
			;;

		*)	
			zrun=y		#Assuming it for running the debug commands. It can be either ALL or product name or class.
			zshift=1
			z_validate "$1"
			;;
	esac

}
		
			

usage () {

#check if,we should print usage message
if [ "$print_usage" = "n" ]
then
	return
fi
echo 'Usage: snap [-@gFGStnfkDpsAliIbBNLRwhHCZXYUM  | -u "user1,..." ] [ -z "product_name=productname, ..." | "class=classname, ..." | ALL ] [-o outputdevice] [-d dir] [All |
file:filename | scriptname1 [scriptname2] ...]'
echo "       snap [-aZ] [-o outputdevice] [-d dir]"
echo "       snap [-gGStnfkDpsAliIbBNLRwhHCZY] [-c] [-O splitsize] [-d dir] [All |
file:filename | scriptname1 [scriptname2] ...]" 
echo "       snap [-o outputdevice] [-d dir]" 
echo "       snap [-v component]"
echo "       snap [-c] [-O splitsize] [-d dir]" 
echo "       snap [-r] [-d dir]" 
echo "       snap [-gGS ]" 
echo "       snap [-gG ]" 
echo "       snap [-gh ]" 
echo "       snap [-gS ]" 
echo "       snap [ -HC | -P files ]" 
echo "       snap [-g] [-T trcfile]" 
echo "       snap [-T trcfile]"
echo '       snap [-u "user1,..."]'
echo "       snap [All]"
echo "       snap [file:filename]"
echo "       snap [scriptname1 [scriptname2] ...]"
echo "       snap [-e [-m nodenamelist]]"
echo "       snap [-U ]\n"
echo '		 snap [ -z ADD "product_name=productname" "class=classname" "command_path=Absolutepathofyourdebugcommand" ]'
echo '		 snap [ -z DELETE "product_name=yourproductname" ]'
echo '		 snap [ -z "product_name=productname, ..." | "class=classname, ..." | ALL ]'
echo '		 snap [ -M snap_time_out_value ]'
echo "\t-@ Gather workload partition information";
echo "\t-a Gather all information."
echo "\t-g Gather general information."
echo "\t-T Captures a specific trace (specify full path name of the trcfile)."
echo "\t-G Include Pd* ODM files in general information."
echo "\t-t Gather tcpip information."
echo "\t-n Gather nfs information."
echo "\t-f Gather file system information."
echo "\t-k Gather kernel information."
echo "\t-D Gather dump and /unix along with livedump information."
if type adump >/dev/null 2>&1
then
	echo "\t-D -x Perform Automated Dump Analysis."
fi
echo "\t-p Gather printer information."
echo "\t-s Gather sna information."
echo "\t-S Include security files in general information."
echo "\t-A Gather async (tty) information."
echo "\t-X Gather X.25 LPP information."
echo "\t-Y Gather IB Debug information."
echo "\t-i Gather Install information."
echo "\t-I Gather PCI-X-SCSI and SISSAS information."
echo "\t-l Gather programming language information."
echo "\t-b Gather SSA Adapter/Disk information."
echo "\t-B Skip SSA adapter dump collection when -b is specified."
echo "\t-R Gather SCSI RAID information."
echo "\t-L Gather logical volume manager (LVM) information."
echo "\t-N Suppress free space checking"
echo "\t-w Gather workload manager (wlm) information."
echo "\t-H Gather general information without platform/scanout data."
echo "\t-C Gather just platform/scanout files."
echo "\t-P Gather just the specified platform/scanout files."
echo "\t-h Gather Hardware information.\n"
echo "\t-e Gather HACMP information."
echo "\t-m node name list [separated by ,] to gather HACMP information.\n"
echo "\t-c Create snap.pax.Z file."
echo "\t-o Send information to removable output device (/dev/rfd0)."
echo "\t-d Directory to put information (/tmp/ibmsupt)."
echo "\t-r Remove directory (/tmp/ibmsupt).\n"
echo "\t-F Gather flash adapter related information.\n"
echo "\t-v Output component snap file to stdout"
echo "\t    Current component choices are:\n\t\t '$complist'\n"
echo "\t-z To run third party debug commands"
echo "\t-M To set the timeout for third party debug commands"
echo "\t   If, used with optoins other than -a/-z its value is ignored"
echo "\t-Z Prevent dump collection.\n"
echo "\t-u Comma seperated usernames whose shell and SMIT history is to be collected"
echo "\t-U Gather Live kernel update information"
}

# ----------------------------------------------------------
# ---------------------  M  A  I  N  -----------------------
# ----------------------------------------------------------


trap intr_action 2

# Save off current umask and set it to 077.
UMASKSAVE=`umask`
umask 077

#Temp files used by -z flag
if [ ! -d "$z_temp_dir" ]
then
	echo "Creating $z_temp_dir directory tree...\c"
	mkdir $z_temp_dir >/dev/null 2>&1
	echo " done."
fi

# take care of quotes in paramers passed with snap
# save the parameter list. Replace any blanks in one
# parameter with commas
parameterlist=$*
saveparamlist=$*

skipSsaAdapterDumpCollection='no' # set to 'yes' by the -B option


while getopts @AaDxT:d:em:fLgGklcnNo:pP:rRv:FsBStXYiIbwhHCO:Ez:M:ZUu: option
do
	if [ $print_usage = n ] && [ $zadd = y -o $zdel = y ]
	then
		#Special check added for VIOS CLI. Error out with processing further for -z ADD/DELETE.
		echo "snap: Error - No options allowed with -z ADD/DELETE."
		# Exit code for VIOS CLI should be more than 100.
		exit 101
	fi
        case $option in

                A)     doasync=y       # Gather async (tty) information
                        action=y
			;;
                a)     doall=y         # Gather all information
			dopred=y
			dosec=y
                        action=y
			;;
                d)     destdir="$OPTARG"      # Directory to put information
                        valid_dir $destdir
                        ;;
                f)     dofs=y          # Gather file system information
                        action=y
                        ;;
                g)     dogen=y         # Gather general information
                        action=y
                        ;;
		G)	dopred=y	# Include predefined ODM database files
			;;
                k)     dokern=y        # Gather kernel information 
                        action=y
                        ;;
                @)     dowpars=y     # Gather wpars information 
                        action=y
                        ;;
                D)     dodump=y        # Gather dump and /unix 
                        action=y
                        ;;
		x)     doadump=y       # Use Automated Dump Analysis
			;;         # always with dodump=y
                l)     dolang=y        # Gather language information
                        action=y
			;;
                c)     dotar=y         # Create info.pax.Z file only
                        action=y
                        ;;
                n)     donfs=y         # Gather nfs information
			doscript=y
                        action=y
                        ;;
		N)	docheck=n	# Suppress free space check
			;;
                o)     devtype="$OPTARG"      # Output Device
                        valid_dev $devtype
                        dodev=y
                        ;;
                p)     doprt=y         # Gather printer information
                        action=y
                        ;;
		P)     doscanonly=y
			scanfiles="$OPTARG"
                        action=y
			;;
                r)     doclean=y       # Remove directory (/tmp/ibmsupt)
                        action=y
                        ;;
                s)     dosna=y         # Gather sna information
                        action=y
                        ;;
		S)	dosec=y		# Include security files in general info
			;;
                t)     dotcp=y         # Gather tcpip information
                        action=y
                        ;;
		T)     domtrace=y
			trcfile="$OPTARG"
                        action=y
			;;
		X)     doXS25=y        # Gather X.25 LPP information
			action=y
                        ;;
		i)     doinst=y        # Gather Install information
			action=y
                        ;; 
		I) 	dopcixscsi=y   # Gather pci-x-scsi information
			dosissas=y     # Gather SISSAS information
		    	action=y 
			;;
		b)     dossa=y         # Gather SSA information
			action=y
			;;
		B)     skipSsaAdapterDumpCollection='yes' # Skip SSA adapter dump collection (ignored if -b not specified)
			;;
                R)     doscraid=y       # Gather scraid information
                        action=y
                        ;;
                L)     dolvm=y		# Gather LVM information
                        action=y
                        ;;
		w)     dowlm=y         # Gather wlm information
			action=y
                        ;;
		h)     dohw=y          # Gather Hardware information
                        ;;
		H)	dogenoscan=y
			action=y
			;;
		C)	doscanonly=y
			action=y
			;;
		e)     dohacmp=y       # Gather HACMP information
			dotar=y
			action=y
			;;
		m)     domflag=y       # Pass node names to clsnap
			nodenames=$OPTARG
			;;
		Y)     doIB=y          # Gather InfiniBand configuration and debug information
			action=y
			;;
		v)	doview=y
			action=y
			component=$OPTARG
			;;
	        O)     dosplit=y
		        let splitsize=$OPTARG*1024*1024
			;;
		Z) 	nodumpcollect=y               # prevent dump collection
			;;
		z)
			dozflag=y
			action=y
			if [ "$OPTARG" = "ADD" -o "$OPTARG" = "DELETE" ]
			then
				shift $(($OPTIND -2))   #Now $1 will be point to ADD/DELETE
				z_parameter "$1" "$2" "$3" "$4"
				shift $(($zshift))      #Skip parameters. zshift is returned by z_parameter
				export OPTIND=1		#Reset OPTIND so that getopts can continue
			else
				z_parameter "$OPTARG"   #Should be the run or ALL option. No special handling.
			fi
			;;
		M)
			cmdtimeout=$OPTARG
			echo $cmdtimeout | grep -E "^[0-9]+$" >/dev/null 2>&1
			if [ $? != 0 ]
			then
				echo "snap: Invalid parameters for -M Option."
				exit 1
			fi
			;;
		F)
			doflash=y
			action=y
			;;
		U)	dolku=y     # Gather Live kernel update information 
			action=y
			;;
		u)	# Gather user history and shell information
			dohist=y
			# Check for custom user list specified in $OPTARG
			# Replace supplied list of users to main user list
			if [[ -n "$OPTARG" ]]; then
				userList="$OPTARG"
			fi
			# Check if supplied comma seperated users are valid
			# Exits snap if invalid user is specifed.
			valid_users $userList
			action=y
			;;
		E)	print_usage=n
			;;
        *)      usage; exit 3

        esac

done

shift $(($OPTIND -1))

if [ -n "$1" ]
then
    doscript=y
    action=y

    while [ -n "$1" ]
    do
	parm=`echo $1 | sed 's/ //g'`
	parameters="$parameters \"$parm\""    # all arguments whether a list or not
						#are enclosed in quotes
	shift;
    done
    set -- $parameters
    # parse script parameter, user may specify file:/path/filename
    # or All or name of script to run. Note that this list does not
    # contain the -- saved to the other list by getopt
    while [ "$doneparsingargs" = n ]
    do

      # save filetype, it will be file if user entered file:/path/filename
      filetype=`echo $1 | awk -F ':' '{print $1}' | sed 's/\"//g'`
      filepath=`echo $1 | awk -F ':' '{print $2}' | sed 's/\"//g'`

      # remove quotes around argument
      arg=`echo $1 | sed 's/\"//g'`

      # All flag specified to run all scripts in repository
      if [ "$arg" = "All" ]
      then

	  allarg=y

	  if [ "$scriptarg" = "y" -o "$filearg" = "y" ]  
	  then
	      doneparsingargs=y
	      mutualexclusion=n
	  
	  else
	      # execute all scripts in scripts directory
	      allscripts=`ls $scriptrepos`
	      for script in $allscripts
	      do
		
		if [[ -f $scriptrepos/$script ]]; then
		scripts="$scripts$script "
		scriptdir=`echo $script | awk -F '' '{print $1}'| sed 's/\"//g'`
		
	        # save the script directory to create
		scriptlist="$scriptlist$scriptdir "
		fi
		
	      done
	  fi 

	  doneparsingargs=y
	  shift;

      else if [ "$filetype" = "file" -a -n "$filepath" ]
      then

	  filearg=y
	  
	  if [ "$scriptarg" = "y" -o "$allarg" = "y" ]  
	  then
	      doneparsingargs=y
	      mutualexclusion=n
	  else 

              # Execute all scripts in the file.
	      /usr/bin/cat $filepath |
	      while read script
	      do
		
		script=`echo $script | 
		awk '
		  NF > 0 {
			for (i=1; i<=NF; i++) {
				printf("%s",$i)
				if (i < NF) printf("")
			}
		}'`
		scripts="$scripts$script "
		scriptdir=`echo $script | awk -F '' '{print $1}'`
		
                # save the script directory to create to list
		scriptlist="$scriptlist$scriptdir "

	      done
	  fi
	  
	  doneparsingargs=y
	  shift;

      else if [ -n "$1" ] # it must be a scriptname
      then
	  scriptarg=y

          if [ "$filearg" = "y" -o "$allarg" = "y" ] 
	  then
	      doneparsingargs=y
	      mutualexclusion=n
	      
	  else
	      # saving script name passed in as argument to snap
	      scripts="$scripts$1 "
	      scriptdir=`echo $1 | awk -F '' '{print $1}' | sed 's/\"//g'`
	      scriptlist="$scriptlist$scriptdir "
	  fi
	  
	  shift;
	  
      else
	  doneparsingargs=y
      fi
      fi
fi

    done
fi

# Add VIOS specific script for -a / -g flags. 
if [ -x "$vioscli" ]
then
	snap_vios=y
	scriptlista="$scriptlista $scriptlista_vios"
	scriptlistg="$scriptlistg $scriptlistg_vios"
fi

# Add in the scripts for -a.
if [ "$doall" = "y" ] 
then
	doscripta=y              # make script name added to dirlist
	scripts="$scripts$scriptlista "
  	for ascript in $scriptlista
  	do
	  scriptdir=`echo $ascript | awk -F '' '{print $1}' | sed 's/\"//g'`
	  scriptlist="$scriptlist$scriptdir "
  	done
fi

# Add in the scripts for -g.
if [ "$dogen" = "y" ]
then
	doscriptg=y              # make script name added to dirlist
	scripts="$scripts$scriptlistg "
	for ascript in $scriptlistg
	do
	  scriptdir=`echo $ascript | awk -F '' '{print $1}' | sed 's/\"//g'`
          scriptlist="$scriptlist$scriptdir "
        done
fi

# Add dumpdata script for -D if it is not specified at command line.
if [ "$dodump" = "y" ]
then
	for ascript in $scripts
	do
	  ascript=`echo $ascript | awk -F '^L' '{print $1}' | sed 's/\"//g'`
	  if [ "$ascript" = "$dumpdatascript" ]
	  then
		isdumpdata=y
		break;
	  fi
	done

	if [ "$isdumpdata" != "y" ]
	then
		scripts="$scripts$dumpdatascript "
		scriptlist="$scriptlist$dumpdatascript "
		dodumpdata=y
	fi
fi

# catch conditions where user specify 2 of All, file:/path/fname,
# list of scriptname
nonparsedargument=n
if  [ "$doneparsingargs" = "y" -a -n "$1" ]
then
    nonparsedargument=y
fi

if [ "$mutualexclusion" = "n" -o "$nonparsedargument" = "y" ]
then
    echo "All, file:<filename> and <scriptname> are mutually exclusive arguments"
    exit 7
fi

if [ "$scriptarg" = "n" -a "$filearg" = "n" -a "$allarg" = "n" -a -n "$2" ]
then
    usage; exit 3
fi

if [ "$dohw" = y -a "$dogen" = n ]
then
	echo "-h option is a modifier to -g option."
        usage
	exit 6
fi

# Make sure dumps are not copied across cluster nodes.
if [ "$dohacmp" = y ] && [ "$dodump" = y -o "$doall" = y ]
then
        echo "It is not recommended to collect system dump over cluster"
        echo "Please specify these actions independently."
        usage
        exit 7
fi

if [ "$domflag" = y -a "$dohacmp" = n ]
then
	echo "-m option is a modifier to -e option."
	usage
	exit 6
fi

if [ "$doadump" = y ]
then
	if ! type adump >/dev/null 2>&1
	then
		echo "Check installed bos.sysmgt.serv_aid package"
		usage
		exit 6
	fi 
fi

if [ "$doadump" = y -a "$dodump" = n ]
then
	echo "-x option is a modifier to -D option."
        usage
	exit 6
fi

if [ "$dotar" = n -a "$dosplit" = y ]
then
    echo "-O option is a modifier to -c option."
    exit 6
fi

# Check for any flags or args
if [ "$action" = n -a "$dodev" = n ]
then
        usage
        exit 4
fi

if [ "$dotar" = y -a "$dodev" = y ]
then
	echo "-c and -o are mutually exclusive options."
	exit 5
fi

if [ "$dogen" = y -o "$dotcp" = y -o "$donfs" = y -o "$dokern" = y -o "$doprt" = y -o "$dodump" = y -o "$dosna" = y -o "$dofs" = y -o "$doasync" = y -o "$dolang" = y -o "$doXS25" = y -o "$doIB" = y -o "$doinst" = y -o "$dossa" = y -o "$doscraid" = y -o "$dolvm" = y -o "$domtrace" = y  -o "$dowlm" = y -o "$dogenoscan" = y -o "$doscanonly" = y -o "$doscript" = y -o "$dopcixscsi" = y -o "$dosissas" = y -o "$dowpars" = y -o "$doflash" = y -o "$dolku" = y -o "$dohist" = y -o "$doper" = y ]
then
    gen_data_sub_command=y
else
    gen_data_sub_command=n
fi

if [ "$gen_data_sub_command" = y -o  "$doall" = y ] && [  "$zadd" =  y -o "$zdel" = y ]
then
	echo "snap: Error: -z ADD/DELETE cannot be used with other options"
	exit 1
fi

if [ "$dohacmp" = y ]
then
        gen_data=y
        if [ "$gen_data_sub_command" = y ]
        then
                clusterwide=y
        else
                clusterwide=n
        fi
        gen_data_sub_command=y
fi

if [ "$doall" = y -o "$gen_data_sub_command" = y -o "$zrun" = y ]
then
    gen_data=y
else
    gen_data=n
fi

#if no -z is used , but -a is set, then all the products should be processed. Set zall=y
if [ "$zrun" != "y" -a "$doall" = "y" ]
then
	zall=y
fi

if [ "$dotar" = y -o "$dodev" = y ]
then
     archive_data=y
else
     archive_data=n
fi

if [ "$doall" = y -a "$gen_data_sub_command" = y ]
then
    usage
    echo "Other data collection flags cannot be used with -a flag."
    exit 7

fi

if [ "$doall" = y ]
then
	dohw=y
fi

#can only have one of $doclean $doview and ($gen_data or $archive_data)
if [ "$doclean" = y ] && [ "$gen_data" = y -o "$archive_data" = y ]
then
    echo "Use -r only with -d."
    exit 6
fi

if [ "$gen_data" = y -o "$archive_data" = y ] && [ "$doview" = y ]
then
	usage
	exit 8
fi

if [ "$doview" = y -a "$doclean" = y ]
then
	usage
	echo "-v and -r are mutually exclusive options."
	exit 8
fi

if [ "$dogen" = y -a "$dogenoscan" = y ]
then
	echo "-g and -H are mutually exclusive options."
	usage
	exit 8
fi

if [ "$dogen" = y -a "$doscanonly" = y ]
then
	echo "Both -g and either the -C or -P flags are specified."
	echo "Using -g, gathers all platform or scan dumps..."
	doscanonly=n
	scanfiles=
fi

#
# Set state action array with appropriate functional actions derived
# from action input arguments. There must be a function associated with 
# each index number.
#

state=""

if [ "$doview" = y ]
then state="$state 100"
fi

if [ "$doclean" = y ]
then state="$state 104"
fi

#Do not add 50 to this list as HACMP runs independently.
if [ "$doall" = y ]
then state="$state 1 2 4 5 6 7 8 9 10 11 12 16 17 18 19 20 21 23 24 25 26 97 98 99 121 122 123 " 
fi

#For InfiniBand
if [ "$doIB" = y ]
then state="$state 123"
fi
if [ "$dogen" = y ]
then state="$state 1 21 99 121 122"
fi
if [ "$dotcp" = y ]
then state="$state 2"
fi
if [ "$dokern" = y ]
then state="$state 4"
fi
if [ "$doprt" = y ]
then state="$state 5"
fi
if [ "$dodump" = y ]
then state="$state 6"
fi
if [ "$dodumpdata" = y ]
then state="$state 99"
fi
if [ "$dosna" = y ]
then state="$state 7"
fi
if [ "$dofs" = y ]
then state="$state 8"
fi
if [ "$doasync" = y ]
then state="$state 9"
fi
if [ "$dolang" = y ]
then state="$state 10"
fi
if [ "$doXS25" = y ]
then state="$state 11"
fi
if [ "$doinst" = y ]
then state="$state 16"
fi
if [ "$dossa" = y ]
then state="$state 17"
fi
if [ "$dolvm" = y ]
then state="$state 18"
fi
if [ "$domtrace" = y ]
then state="$state 19"
fi
if [ "$dowlm" = y ]
then state="$state 20"
fi
if [ "$doscraid" = y ]
then state="$state 22"
fi
if [ "$dowpars" = y ]
then state="$state 23"
fi
if [ "$dogenoscan" = y ]
then state="$state 1 121 122"
fi
if [ "$doscanonly" = y ]
then state="$state 21"
fi
if [ "$dohacmp" = y ]
then state="$state 50"
fi
if [ "$doall" != y -a "$dohist" = y ]
then state="$state 97"
fi
if [ "$dolku" = y ]
then state="$state 98"
fi
if [ "$doscript" = y ]
then
    if [ "$donfs" = y ]
    then
	scripts=`echo "$scripts nfs"`
    fi
    state="$state 99"
fi
if [ "$dopcixscsi" = y ]
then state="$state 121"
fi
if [ "$dosissas" = y ]
then state="$state 122"
fi
if [ "$doper" = y ]
then state="$state 26"
fi
# These should always be at the last so that all the data
# Collected above goes here.

if [ "$dotar" = y ]
then state="$state 102"
fi
if [ "$dodev" = y ]
then state="$state 103"
fi
if [ "$dozflag" = y -a "$doall" != y ]
then
	state="$state 24"	#Add the state only if -a is not used. Else will be processed twice.
fi

# Special Case for collecting data across cluster nodes.
if [ "$clusterwide" = y ]
then 
  state="50"
  docheck=n
fi
if [ "$doflash" = y ]
then state="$state 25"
fi

#
# State machine is built. First check for enough free space.
# This is pass 1 on state functions.
#
# If any gathering flags then check space requirements
if [ "$docheck" = y ]
then
	if [ "$gen_data" = y ]
	then
		passno=1
		for i in $state
		do
			# don't check size of overhead stuff.
       			if [ "$i" -lt 100 ] 
       	 		then
       	         		state_func${i} 
       	 		fi
		done
		echo "Checking for enough free space in filesystem...\c"
# adding an extra 20000 bytes into total number of bytes needed in order to
# keep filesystem from being 100 percent full on systems tight on space
		total_bytes=`expr $total_bytes + 20000`
		ckspace 
	fi
else
	if [ "$gen_data" = y ]
	then

		echo "\nSpace checking has been suppressed... continuing"
		passno=2
	else
		usage
		exit 9
	fi
fi

# If any gathering flags then initialize the destination directory 
if [ "$gen_data" = y ]
then
	echo 
       	initial_setup
fi

#
# Now proceed to call the associated functions for real.
# This is pass 2 on state functions.
#
passno=2
for i in $state
do
	state_func${i}
done
	
z_remove_tmp
# Set the umask back to the original value.
umask $UMASKSAVE

exit 0
# End of snap

