diff --git a/cluster/disable.host.queue.sh b/cluster/disable.host.queue.sh index 73cca1e..696e507 100755 --- a/cluster/disable.host.queue.sh +++ b/cluster/disable.host.queue.sh @@ -6,7 +6,7 @@ readonly PROGDIR=$(readlink -m $(dirname "${0}")) readonly ARGS="${*}" readonly NBARGS="${#}" ## Test if DEBUG is already defined (by parent script,…) -[ -z "${DEBUG}" ] && readonly DEBUG=1 +[ -z "${DEBUG}" ] && readonly DEBUG=0 ## Colors readonly PURPLE='\033[1;35m' @@ -97,15 +97,15 @@ state is: ${RED}${local_sge_queue_state:=/dev/null}${COLOR_DEBUG}." # }}} is_queue_disable() { # {{{ - local_sge_hostname="${1}" - local_sge_queue_name="${2}" + local_queue_disable_hostname="${1}" + local_queue_disable_name="${2}" ## List all queues with 'disable' state and filter to the expected queue name - ## with a fake_user to avoid pending jobs for this queue + ## add a fake_user to avoid pending jobs for this queue ### And count returned lines - local_sge_queue_test=$(qstat -f -qs d -q "${local_sge_queue_name:=/dev/null}@${local_sge_hostname:=/dev/null}" -u fake_user \ + local_queue_disable_test=$(qstat -f -qs d -q "${local_queue_disable_name:=/dev/null}@${local_queue_disable_hostname:=/dev/null}" -u fake_user \ | wc -l) - case "${local_sge_queue_test}" in + case "${local_queue_disable_test}" in 0 ) ## No result so the queue is enable local_sge_queue_state="enable" return_queue_disable="1" @@ -115,18 +115,40 @@ is_queue_disable() { # {{{ return_queue_disable="0" ;; * ) ## Unexpected result - printf '%b\n' "${RED}Not able to determine the state of ${local_sge_queue_name:=/dev/null}@${local_sge_hostname:=/dev/null} queue (command return ${local_sge_queue_test} lines).${RESET}" + printf '%b\n' "${RED}Not able to determine the state of ${local_queue_disable_name:=/dev/null}@${local_queue_disable_hostname:=/dev/null} queue (command return ${local_queue_disable_test} lines).${RESET}" exit 3 ;; esac ## Simple debug message to valid current variables debug_message "is_queue_disable − \ -SGE queue: ${RED}${local_sge_queue_name:=/dev/null}${COLOR_DEBUG} \ +SGE queue: ${RED}${local_queue_disable_name:=/dev/null}${COLOR_DEBUG} \ state is: ${RED}${local_sge_queue_state:=/dev/null}${COLOR_DEBUG}." return "${return_queue_disable}" +} +# }}} +is_all_queue_disable() { # {{{ + + local_all_queue_disable_hostname="${1}" + local_all_queue_disable_name="${2}" + + ## By default, all queues are disable + return_all_queue_disable="0" + + ## Test all queues one by one + for loop_disable_queue in ${local_all_queue_disable_name}; do + + ### If a queue is not disable + #### Change the return value + is_queue_disable "${local_all_queue_disable_hostname}" "${loop_disable_queue}" \ + || return_all_queue_disable="1" + + done + + return "${return_all_queue_disable}" + } # }}} disable_sge_queue() { # {{{ @@ -150,18 +172,22 @@ main() { # {{{ manage_args "${ARGS}" - sge_queue_name="$(qhost -h "${sge_hostname:=/dev/null}" -q -xml \ + sge_queues_name="$(qhost -h "${sge_hostname:=/dev/null}" -q -xml \ | grep "queue name" \ | cut -d"'" -f2 )" + sge_queues_name_print="$(qhost -h "${sge_hostname:=/dev/null}" -q -xml \ + | grep "queue name" \ + | cut -d"'" -f2 \ + | tr -s '\n' ' ' )" ## Simple debug message with color to valid current variables debug_message "main − Try to manage \ -SGE queue: ${RED}${sge_queue_name:=/dev/null}${COLOR_DEBUG} \ +SGE queue(s): ${RED}${sge_queues_name_print:=/dev/null}${COLOR_DEBUG}\ for host: ${RED}${sge_hostname:=/dev/null}${COLOR_DEBUG}." - ## If the queue is already disable + ## If the queue are already disable ### Exit - is_queue_disable "${sge_hostname}" "${sge_queue_name}" \ + is_all_queue_disable "${sge_hostname}" "${sge_queues_name}" \ && exit 0 ## If the queue is enable