#! /bin/bash

# Set your our black list
#     hostname w/o domain name, e.g. lnxXXX
# If "BLACK_LIST" is empty, then this script will enable
# all slots.
#
BLACK_LIST='lnx326 lnx306'
#BLACK_LIST=

##############################################################################
wc_queue_list=
##############################################################################
# All configured queues
#   Q=`qconf -sql`
# I assume it's "all.q"
#
declare -a array_host
declare -a array_black_list
array_black_list=($BLACK_LIST)

Q='all.q'
EXECUTION_HOSTS=`qconf -sel`
array_host=($EXECUTION_HOSTS)

get_wc_queue_list()
{

    i=0
    nhost=0
    for iHOST in ${array_host[@]} ;
      do
      host=`echo $iHOST | cut -f1 -d.`
      
      exclude=0
      for iBLACK in ${array_black_list[@]} ;
	do
	black=`echo $iBLACK | cut -f1 -d.`
	if [ "$black" = "$host" ]; then
	    exclude=1
	    break
	fi
      done
      
      if [ $exclude -eq 0 ]; then
	  if [ $nhost -eq 0 ]; then
	      wc_queue_list="$Q@$iHOST"
	  else
	      wc_queue_list="$wc_queue_list,$Q@$iHOST"
	  fi
	  nhost=$((nhost + 1))
      fi
      
#      echo "HOST $i = " $host
      i=$((i + 1))
    done

#
echo "wc_queue_list = $wc_queue_list"
#
echo "number of wc_queue = $nhost /  $i"

}
##############################################################################

if [ "$BLACK_LIST" = '' ]; then
    wc_queue_list="$Q"'@*'
else
    get_wc_queue_list
fi

# now you have the list of wc_queue

# if you apply the black list to your all pending jobs in the queue
#
#qalter -u $USER -q $wc_queue_list

# or if you just want to apply the black list to a job
# qalter -q $wc_queue_list JOB_NAME
