#!/usr/bin/ksh
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# bos72F src/bos/usr/sbin/ssdCache/cacheMgt/cache_mgt/cache_mgt_collect.sh 1.4 
#  
# Licensed Materials - Property of IBM 
#  
# Restricted Materials of IBM 
#  
# COPYRIGHT International Business Machines Corp. 2016,2017 
# 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 

#set -x
export CACHE_MGT="/usr/sbin/cache_mgt"
export LSLPP="/usr/bin/lslpp" 
export ODMGET="/usr/bin/odmget"  
export CP="/usr/bin/cp" 

dump_cache_mgt_levels()
{
       echo "--------------------------------------------------\n"
       echo "cache.mgt.rte fileset levels\n"
       echo "--------------------------------------------------\n"
       ${LSLPP} -l cache.mgt.rte 
}

dump_cache_mgt_cmd()
{
        #1: Dump List Of SSD Devices on the system, reported by cache_mgt
        echo "\n--------------------------------------------------\n" 
        echo "${CACHE_MGT} device list\n" 
        echo "--------------------------------------------------\n" 
        ${CACHE_MGT} device list 
        echo "--------------------------------------------------\n" 
        echo "${CACHE_MGT} device list -l\n" 
        echo "--------------------------------------------------\n" 
        ${CACHE_MGT} device list -l


        #2: Dump List of cache pools reported
        echo "\n\n--------------------------------------------------\n" 
        echo "${CACHE_MGT} pool list\n" 
        echo "--------------------------------------------------\n" 
        ${CACHE_MGT} pool list 
        echo "--------------------------------------------------\n"
        echo "${CACHE_MGT} pool list -l\n"
        echo "--------------------------------------------------\n"
        ${CACHE_MGT} pool list -l


        #3: Dump List of partitions 
        echo "\n\n--------------------------------------------------\n" 
        echo  "${CACHE_MGT} partition list \n"
        echo "--------------------------------------------------\n" 
        ${CACHE_MGT} partition list 
        echo "\n--------------------------------------------------\n" 
        echo  "${CACHE_MGT} partition list -l \n" 
        echo "--------------------------------------------------\n" 
        ${CACHE_MGT} partition list -l

        #4: Dump List of caches
        echo "\n\n--------------------------------------------------\n" 
        echo  "${CACHE_MGT} cache list \n" 
        echo "--------------------------------------------------\n" 
        ${CACHE_MGT} cache list 

}

if [ "$PASSNO" = 1 ]; then
	#
	# Handle AIX snap's first pass, which requests a size estimate of the
	# total expected data to be collected. 45 MB.
	#
	typeset -i total_bytes=47185920

	#
	# Report the size estimate through the SCRIPTSIZE environment variable.
	#
	echo "$total_bytes" >$SCRIPTSIZE

elif [ "$PASSNO" = 2 ]; then
	#
	# Handle AIX snap's second pass, which collects the data.
	#

	#
	# Put snap data, and log any progress where AIX snaps wants it
	# ($SNAPDIR and $SCRIPTLOG, respectively). Subdirectories should
	# be placed under $SNAPDIR, and log data should be *appended* to
	# $SCRIPTLOG (e.g. echo "whatever" >>$SCRIPTLOG).
	#
        #1: Collect ODM related CuDv, CuAt
        ${ODMGET} CuDv > $SNAPDIR/cudv
        ${ODMGET} CuAt > $SNAPDIR/cuat

        #2: Collect cache_mgt command output
        dump_cache_mgt_cmd > $SNAPDIR/cache_mgt_cmd.out 2>&1

        #3: Collect cache_mgt fileset levels  
        dump_cache_mgt_levels > $SNAPDIR/cache_mgt_level.out 2>&1
      
        #4: Collect existing cache_mgt cmd history
        ${CP} /var/adm/ras/pfc/cache_mgt.log* $SNAPDIR 

else
	echo "This script must be run under AIX snap." 
	exit 1
fi
