Par de soluciones en BASH4+
# -- server available to check via port xxx ? --
function isServerAvailableNC() {
max_secs_run="${3}"
if timeout $max_secs_run nc -z ${1} ${2} 2>/dev/null >/dev/null; then
#echo "${1} ✓"
true
else
#echo "${1} ✗"
return
fi
}
# -- server available to check via port xxx ? --
# -- supported protocols (HTTP, HTTPS, FTP, FTPS, SCP, SFTP, TFTP, DICT, TELNET, LDAP or FILE) --
#/usr/bin/curl -sSf --max-time 3 https://ifwewanted.to.confirm.https.com/ --insecure
function isServerAvailableCURL() {
max_secs_run="${3}"
proto="http://"
if [ ! -z ${2} ] || [ ${2} -gt 80 ] ;then
proto="https://"
fi
if /usr/bin/curl -sSf --max-time "${max_secs_run}" "${1}" --insecure 2>/dev/null >/dev/null; then
#echo "${1} ✓"
true
else
#echo "${1} ✗"
false
fi
}
Ejemplo de uso:
RECOMENDAR QUE se use NC si necesitamos un puerto específico
host="1.2.3.4"
if isServerAvailableCURL "$host" "80" "3";then
check_remote_domain_cert "$host"
fi
host="1.2.3.4"
if isServerAvailableNC "$host" "80" "3";then
check_remote_domain_cert "$host"
fi