#!/usr/bin/ksh
####################################################################################
# This script is used to get the arrays seen by each Unix San control workstation
# The output is  $OUT file used for the main script srdf_link_check
####################################################################################
#
DIR=/gsmsan04/cob_logs/srdf_link_logs/tmp
#
####################################

Usage()
{
#set -x
#tput clear
[[ -n "$1" ]] && print "\n\n$(basename $0): $@ \n "
print "\n\n $(basename $0) -c <collect> \n"
print " arguments: "
print "            -c    <collect>     : Indicates  to collect the information of the Arrays per Unix SAN workstation   \n "
print " \n\n  sample usage is $(basename $0) -c collect \n\n"
print "\t The Output file is  ${DIR}/local_arrays_<mmddyy> \n"
print "\t This script is used to generate the Array information for srdf_link_check script \n"
exit 1
}

os_type()
{
#set -x
os=`/usr/bin/uname`
osver=`/usr/bin/uname -a|awk '{print $3}'`
   case $os in

                SunOS) export PATH=/usr/xpg4/bin:$PATH
                       if [[ "$osver" = "5.8" ]];then
                            wgrep=`echo "grep -Ew "`
                       else
                            wgrep=`echo "grep -w "`
                       fi
                       export wgrep ;;
                  AIX) wgrep=`echo "egrep -w "`
                       export wgrep ;;
  esac
}

Arg()
{
#set -x
        [[ $# = 0 ]] && Usage
        while getopts :c: OPT; do
                case $OPT in
                         c) check=$OPTARG ;;
                        \?) Usage $@ ;;
                esac
        done
shift OPTIND-1

   if [[  "$check"  != "collect" ]];then
        Usage "Error: Incorrect argument used on `hostname` : Please check the argument"
   fi
tag=`id |egrep uid | sed 's/=/ /g'|awk '{print $2}'|awk -F'(' '{print $1}'`

if [[ "$tag" -eq 0 ]];then
     vpbrun=""
else
    vpbrun="pbrun"
fi

host=`hostname`
OUT=$DIR/local_arrays_`date +"%m%d%y"`
}

Main(){
#set -x

 $vpbrun symcfg list |egrep Local |awk '{print $1}' |sed -e "s/^/$host:/g" >>$OUT
chmod 666 $OUT
}

os_type
Arg $@
Main

