Move some vars def to define_vars function

This commit is contained in:
Jeremy Gardais 2020-09-25 13:39:27 +02:00
parent 7f8947dac9
commit fed34bae66
Signed by: jegardai
GPG Key ID: E759BAA22501AF32
1 changed files with 19 additions and 23 deletions

View File

@ -67,6 +67,19 @@ define_vars() { # {{{
sge_hostname="$(hostname -f)" sge_hostname="$(hostname -f)"
fi fi
## Script used to disable SGE queue(s)
sge_disable_host_queue_script="${PROGDIR}/sge.disable.host.queue.sh"
## Get the number of total SGE slots
sge_slots=$(qhost -h "${sge_hostname:=/dev/null}" -q -xml \
| grep --max-count=1 -- "'slots'" \
| sed 's;.*<queuevalue.*>\(.*\)</queuevalue>;\1;')
## Get the number of SGE used slots
sge_slots_used=$(qhost -h "${sge_hostname:=/dev/null}" -q -xml \
| grep --max-count=1 -- "'slots_used'" \
| sed 's;.*<queuevalue.*>\(.*\)</queuevalue>;\1;')
} }
# }}} # }}}
is_apt_upgrade_absent() { # {{{ is_apt_upgrade_absent() { # {{{
@ -121,31 +134,21 @@ is_sge_slots_more_than_percentage() { # {{{
local_percentage="${1}" local_percentage="${1}"
## Get the number of total SGE slots
local_sge_slots=$(qhost -h "${sge_hostname:=/dev/null}" -q -xml \
| grep --max-count=1 -- "'slots'" \
| sed 's;.*<queuevalue.*>\(.*\)</queuevalue>;\1;')
## Get the expected percentage of total SGE slots ## Get the expected percentage of total SGE slots
local_sge_slots_percentage=$(echo "${local_sge_slots}" \ local_sge_slots_percentage=$(echo "${sge_slots}" \
| awk -v percentage="0.${local_percentage}" '{ print int($1 * percentage) }') | awk -v percentage="0.${local_percentage}" '{ print int($1 * percentage) }')
## Get the number of SGE used slots if [ "${sge_slots_used}" -ge "${local_sge_slots_percentage}" ]; then
local_sge_slots_used=$(qhost -h "${sge_hostname:=/dev/null}" -q -xml \
| grep --max-count=1 -- "'slots_used'" \
| sed 's;.*<queuevalue.*>\(.*\)</queuevalue>;\1;')
if [ "${local_sge_slots_used}" -ge "${local_sge_slots_percentage}" ]; then
## Used slots is greater or equal than expected percentage ## Used slots is greater or equal than expected percentage
return_sge_slots_percentage="0" return_sge_slots_percentage="0"
## Simple debug message to valid current variable ## Simple debug message to valid current variable
debug_message "is_sge_slots_more_than_percentage \ debug_message "is_sge_slots_more_than_percentage \
Used slots has reached ${RED}${local_percentage}%${COLOR_DEBUG} of total slots: ${RED}${local_sge_slots_used:=/dev/null}${COLOR_DEBUG}/${local_sge_slots}." Used slots has reached ${RED}${local_percentage}%${COLOR_DEBUG} of total slots: ${RED}${sge_slots_used:=/dev/null}${COLOR_DEBUG}/${sge_slots}."
else else
return_sge_slots_percentage="1" return_sge_slots_percentage="1"
## Simple debug message to valid current variable ## Simple debug message to valid current variable
debug_message "is_sge_slots_more_than_percentage \ debug_message "is_sge_slots_more_than_percentage \
Used slots did not reach ${RED}${local_percentage}%${COLOR_DEBUG} of total slots: ${RED}${local_sge_slots_used:=/dev/null}${COLOR_DEBUG}/${local_sge_slots}." Used slots did not reach ${RED}${local_percentage}%${COLOR_DEBUG} of total slots: ${RED}${sge_slots_used:=/dev/null}${COLOR_DEBUG}/${sge_slots}."
fi fi
return "${return_sge_slots_percentage}" return "${return_sge_slots_percentage}"
@ -180,12 +183,7 @@ NO pending upgrades for more than ${RED}${local_days:=/dev/null}${COLOR_DEBUG} d
# }}} # }}}
is_sge_slots_empty() { # {{{ is_sge_slots_empty() { # {{{
## Get the number of SGE used slots if [ "${sge_slots_used}" -eq "0" ]; then
local_sge_slots_used=$(qhost -h "${sge_hostname:=/dev/null}" -q -xml \
| grep --max-count=1 -- "'slots_used'" \
| sed 's;.*<queuevalue.*>\(.*\)</queuevalue>;\1;')
if [ "${local_sge_slots_used}" -eq "0" ]; then
## Used slots is null ## Used slots is null
return_sge_slots_empty="0" return_sge_slots_empty="0"
else else
@ -194,7 +192,7 @@ is_sge_slots_empty() { # {{{
## Simple debug message to valid current variable ## Simple debug message to valid current variable
debug_message "is_sge_slots_empty \ debug_message "is_sge_slots_empty \
SGE slots currently in use: ${RED}${local_sge_slots_used:=/dev/null}${COLOR_DEBUG}." SGE slots currently in use: ${RED}${sge_slots_used:=/dev/null}${COLOR_DEBUG}."
return "${return_sge_slots_empty}" return "${return_sge_slots_empty}"
@ -229,8 +227,6 @@ main() { # {{{
## Define all vars ## Define all vars
define_vars define_vars
sge_disable_host_queue_script="${PROGDIR}/sge.disable.host.queue.sh"
## If NO APT package upgrade is available {{{ ## If NO APT package upgrade is available {{{
### Ensure to remove any temp file related to APT upgrades ### Ensure to remove any temp file related to APT upgrades
### Exit ### Exit