#!/bin/ksh
#
# XARY aka Andrei.Ryjov@spasu.net Tue Oct  7 07:26:39 CEST 2008
#
# check if $RESERVE gb is too large so rthat we can give up some LUNs
#
uname -s | egrep -s AIX || exit 0       # Run on AIX only

TODAY=`date +%Y%m%d`
LASTRUNFILE=/var/tmp/`basename $0`.lastrun
touch $LASTRUNFILE
[ x"`cat $LASTRUNFILE`" = x"$TODAY" ] && exit 0 # Reduce the noise bu running once a day only
echo $TODAY >$LASTRUNFILE


#
# If there are ANY dlm* PVs, grep for dlm | None, otherwise just for None
#
FREELUNS=`lspv | awk '$1~/^dl/ && $2=="none" && $3=="None"'`; lspv | egrep -s dl || FREELUNS=`lspv | awk '$2=="none" && $3=="None"'`

FREELUNS=`echo "$FREELUNS" | awk '{print $1}'`

for i in `echo $FREELUNS`; do
  #
  # If an unallocated LUN is a dlmfdrv, then just add it to message,
  # otherwise make sure this is not an internal SCSI disk.. Then add


  echo $i | egrep -s dl && MESSAGE="$MESSAGE\n$i\n" || {
    lsdev -l $i | egrep -s SCSI || MESSAGE="$MESSAGE\n$i\n"
  }
done

[ `echo "$MESSAGE" | wc -w` -lt 1 ] && exit 0

printf "Unallocated LUNs\n\n$MESSAGE\n"
exit 1
