From e96c9ff54807c853776c8251821bc55f806614d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gardais=20J=C3=A9r=C3=A9my?= Date: Wed, 24 Jun 2020 14:53:53 +0200 Subject: [PATCH] Test if given hostname is the current host --- cluster/sge.disable.host.queue.sh | 35 ++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/cluster/sge.disable.host.queue.sh b/cluster/sge.disable.host.queue.sh index 7e10fa6..96a20d8 100755 --- a/cluster/sge.disable.host.queue.sh +++ b/cluster/sge.disable.host.queue.sh @@ -61,6 +61,17 @@ define_vars() { # {{{ sge_hostname="$(hostname -f)" fi + ## If the host to manage is the current one + if is_current_host "${sge_hostname}" ; then + debug_message "define_vars − \ +${sge_hostname} is the current host." + LOCAL_HOST="0" + else ## In case of a remote host + debug_message "define_vars − \ +${sge_hostname} is not the current host." + LOCAL_HOST="1" + fi + ## Get all queues name sge_queues_name="$(qhost -h "${sge_hostname:=/dev/null}" -q -xml \ | grep "queue name" \ @@ -70,6 +81,22 @@ define_vars() { # {{{ | cut -d"'" -f2 \ | tr -s '\n' ' ' )" +} +# }}} +is_current_host() { # {{{ + + local_current_host="${1}" + local_current_fqdn=$(hostname -f) + + ## Test if the sge_host to manage is the current host + if [ "${local_current_host}" = "${local_current_fqdn}" ]; then + local_current_host_return="0" + else + local_current_host_return="1" + fi + + return "${local_current_host_return}" + } # }}} is_queue_enable() { # {{{ @@ -172,8 +199,14 @@ disable_sge_queue() { # {{{ Try to disable SGE queue: ${RED}${local_sge_queue_name:=/dev/null}@${local_sge_hostname:=/dev/null}${COLOR_DEBUG}." ## SGE command to disable the queue + ## and get returned value + ## and create a file for local queue qmod --disable "${local_sge_queue_name}@${local_sge_hostname}" > /dev/null \ - && return_disable_queue="${?}" + && return_disable_queue="${?}" \ + && { + [ "${LOCAL_HOST}" -eq "0" ] && printf '%s' "by ${PROGNAME} script" > "${sge_queue_deactivator}" + } + return "${return_disable_queue}"