34 / 55 · 19 Linux & Command Line · Bash Scripting for QA← prev⊞ allnext →☰ Read as one page
5.4Functions
# Define a function
check_health() {
local env=$1
local url="https://${env}.example.com/health"
local status
status=$(curl -s -o /dev/null -w "%{http_code}" --max-time 30 "$url")
if [ "$status" -eq 200 ]; then
echo "PASS: $env ($status)"
return 0
else
echo "FAIL: $env ($status)"
return 1
fi
}
# Call the function
check_health "staging"
check_health "production"