#! /usr/bin/ksh

#--------------------------------------------------------------------#
#  DISCLAIMER                                                        #
#                                                                    #
#  This script was written for a specific task and environment.      #
#  There is no gaurantee that the script will work correctly or      #
#  for that matter not do damage.  It is the responsibility of       #
#  the system administrator to review the script and insure that     #
#  it will work correctly in his/her environment.                    #
#                                                                    #
#  The author accepts no responsibility for this script in any       #
#  environment that he has not directly placed this script.          #
#                                                                    #
#--------------------------------------------------------------------#

#--------------------------------------------------------------------#
#                                                                    #
# Written: Itrus Technologies, Inc. (www.itrus.net)                  #
#    Date:                                                           #
#                                                                    #
# Purpose:                                                           #
#                                                                    #
#                                                                    #
#  Remove: Indefinite Lifespan                                       #
#--------------------------------------------------------------------#

if [[ '-x' = "$1" ]]
then
	set -x                          # Turn on debugger
	typeset -ft $(typeset +f)       # Turn on debugger for all functions
	DFLAG="-x"                      # Setup a debug flag to pass to script calls
	shift
fi

unalias -a

if (( $( id -u ) ))
then
		print -u2 "Must be run as root"
		exit 0
fi

export PATH=$PATH:/usr/ios/cli:/usr/ios/utils:/usr/ios/lpm/bin:/usr/ios/oem:/usr/ios/ldw/bin:/root/bin:/root/sbin:/home/padmin

mkdir /tmp/free_disks 2> /dev/null
cd /tmp/free_disks || exit $?

lsdev -Cc disk -S available | awk '!/EMC/{print $0}' > all
#lsdev -Cc disk -S available | awk '/power/{print $1}' >> all

ioscli lsmap -all | awk '/hdisk/{print "^"$NF}' > used
lspv | grep -iwv none | awk '{print "^"$1}' >> used  

grep -wvf used all
grep -wvf used all > free

exit 0
