forked from johnlokerse/website-healthcheck
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscan-website.sh
More file actions
executable file
·46 lines (38 loc) · 1.12 KB
/
scan-website.sh
File metadata and controls
executable file
·46 lines (38 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
website_url=$1
scan_text=$2
max_attempts=$3
backoff_multiplier=$4
json_checks=$5
for (( i=1; i<=$max_attempts; i++ )); do
sleep_duration=$(($i * $backoff_multiplier))
body=$(curl --silent --location --fail "${website_url}")
if [ $? -ne 0 ]; then
echo "Website is unreachable" >&2
sleep $sleep_duration
continue
fi
failed=false
if [ -n "${scan_text}" ]; then
if ! echo "$body" | grep --quiet --ignore-case "${scan_text}"; then
echo "Text '${scan_text}' was not found on website" >&2
failed=true
fi
fi
if [ -n "${json_checks}" ]; then
while IFS= read -r check; do
[ -z "$check" ] && continue
key="${check%%=*}"
expected="${check#*=}"
actual=$(echo "$body" | jq -r ".${key}")
if [ "$actual" != "$expected" ]; then
echo "Check failed: ${key} expected '${expected}', got '${actual}'" >&2
failed=true
fi
done <<< "$json_checks"
fi
if [ "$failed" = false ]; then
exit 0
fi
sleep $sleep_duration
done
exit 1