Test if given hostname is the current host

This commit is contained in:
Jeremy Gardais 2020-06-24 14:53:53 +02:00
parent 3d6d8de497
commit e96c9ff548
Signed by: jegardai
GPG Key ID: E759BAA22501AF32
1 changed files with 34 additions and 1 deletions

View File

@ -61,6 +61,17 @@ define_vars() { # {{{
sge_hostname="$(hostname -f)" sge_hostname="$(hostname -f)"
fi 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 ## Get all queues name
sge_queues_name="$(qhost -h "${sge_hostname:=/dev/null}" -q -xml \ sge_queues_name="$(qhost -h "${sge_hostname:=/dev/null}" -q -xml \
| grep "queue name" \ | grep "queue name" \
@ -70,6 +81,22 @@ define_vars() { # {{{
| cut -d"'" -f2 \ | cut -d"'" -f2 \
| tr -s '\n' ' ' )" | 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() { # {{{ 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}." 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 ## 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 \ 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}" return "${return_disable_queue}"