Replace awk by grep to check hostname:port

This commit is contained in:
Jeremy Gardais 2023-02-27 11:40:35 +01:00
parent 2a940cc20c
commit fec56cdee6
Signed by: jegardai
GPG Key ID: E759BAA22501AF32
1 changed files with 4 additions and 7 deletions

View File

@ -147,13 +147,9 @@ define_vars() { # {{{
error_message "iDrac host can't be empty, please check your input or use --host option. For more informations, see the help message (--help)." 11
fi
## }}}
## If idrac_host_temp is still empty {{{
if [ -z "${idrac_host_temp-}" ]; then
error_message "iDrac host can't be empty, please check your input or use --host option. For more informations, see the help message (--help)." 11
fi
## }}}
## If idrac_host_temp contains a port number {{{
if printf '%b' "${idrac_host_temp}" | awk 'BEGIN { FS = ":" } ; /^[a-zA-Z]+.*:[0-9]+$/' >/dev/null; then
if printf '%b' "${idrac_host_temp}" | grep --extended-regexp '^[a-zA-Z]+.*:[0-9]+$' >/dev/null; then
debug_message "- Try to extract hostname and port number from value (${RED}${idrac_host_temp}${COLOR_DEBUG})."
### Extract hostname and port number
idrac_host=$(printf '%b' "${idrac_host_temp}" | awk 'BEGIN { FS = ":" } ; /^[a-zA-Z]+.*:[0-9]+$/ { print $1 }')
idrac_port=$(printf '%b' "${idrac_host_temp}" | awk 'BEGIN { FS = ":" } ; /^[a-zA-Z]+.*:[0-9]+$/ { print $2 }')
@ -290,8 +286,9 @@ main() { # {{{
## }}}
## Define all vars
debug_message "| Define vars BEGIN"
define_vars
debug_message "| Define vars"
debug_message "| Define vars END"
debug_message "| Given informations are :
idrac_host: ${RED}${idrac_host}${COLOR_DEBUG}