SEARCH_STRING added to generic URL_CHECK

This commit is contained in:
Martin Berghaus
2025-11-05 23:37:10 +01:00
parent f5fac41996
commit 6e04900fc7

View File

@@ -13,18 +13,28 @@
# -q Quite, no output just status codes # -q Quite, no output just status codes
# -F Interpret search term as plain text # -F Interpret search term as plain text
function checkUrl() { function checkUrl() {
local _URL local _URL _SEARCH_STRING
_URL="${1:?"URL of site missing"}" _URL="${1:?"URL of site missing"}"
readonly _URL _SEARCH_STRING="${2}"
readonly _URL _SEARCH_STRING
local _RESULT local _RESULT
_RESULT="$(curl --connect-timeout 10 --max-time 10 --head --no-progress-meter --verbose "${_URL}" 2>&1 | grep -o -E '(expire.*|^HTTP.*200 OK)')" if [ -z "${_SEARCH_STRING}" ]; then
_RESULT="$(curl --connect-timeout 10 --max-time 10 --no-progress-meter --verbose "${_URL}" 2>&1 | grep -o -E "(expire.*|HTTP.*200 OK)")"
else
_RESULT="$(curl --connect-timeout 10 --max-time 10 --no-progress-meter --verbose "${_URL}" 2>&1 | grep -o -E "(expire.*|HTTP.*200 OK|${_SEARCH_STRING})")"
fi
readonly _RESULT readonly _RESULT
! echo "${_RESULT}" | grep -q -F '200 OK' \ ! echo "${_RESULT}" | grep -q -F '200 OK' \
&& echo "FAIL#Status code 200 not found" \ && echo "FAIL#Status code 200 not found" \
&& return 1 && return 1
! [ -z "${_SEARCH_STRING}" ] \
&& ! echo "${_RESULT}" | grep -q -F "${_SEARCH_STRING}" \
&& echo "FAIL#Search string not found" \
&& return 1
local _ENDDATE local _ENDDATE
_ENDDATE="$(echo "${_RESULT}" | grep -F 'expire' | cut -d':' -f2-)" _ENDDATE="$(echo "${_RESULT}" | grep -F 'expire' | cut -d':' -f2-)"
_ENDDATE="$(date --date="${_ENDDATE}" --utc +%s)" _ENDDATE="$(date --date="${_ENDDATE}" --utc +%s)"
@@ -49,4 +59,4 @@ function checkUrl() {
} }
#((curl --connect-timeout 10 --max-time 10 -k -s --head --no-progress-meter "${_URL}" | grep -qF '200 OK') && echo OK) || echo FAIL #((curl --connect-timeout 10 --max-time 10 -k -s --head --no-progress-meter "${_URL}" | grep -qF '200 OK') && echo OK) || echo FAIL
checkUrl "${@}" && exit 0 || exit 1 checkUrl "${1}" "${2}" && exit 0 || exit 1