You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Princeton/pu-check-website

51 lines
1.4 KiB
Bash

#!/bin/sh
#
# curl -c /tmp/cookie.txt --location -k "https://oampfsqual.princeton.edu:443/psp/pfsqual/EMPLOYEE/ERP/" | grep "Central Authentication Service"
http="http"
port="80"
host=""
uri=""
search=""
while getopts ":SH:u:s:p:" OPTION; do
case "$OPTION" in
S) http="https"; port=443;;
H) host="$OPTARG";;
u) uri="$OPTARG";;
s) search="$OPTARG";;
p) port="$OPTARG";;
esac
done
[ -z "$http" ] && echo "Error - invalid protocol ($http)" && exit 3
[ -z "$host" ] && echo "Error - invalid host ($host)" && exit 3
[ -z "$port" ] && echo "Error - invalid port ($port)" && exit 3
tmpfile="/tmp/cookies.txt.$$"
rm -Rf $tmpfile
URL="$http://$host:$port$uri"
output_format="%{size_download} bytes in %{time_total} second response time |time=%{time_total}s;;;0.000 size=%{size_download}B;;;0"
output=`curl --silent -o $tmpfile.output -w "$output_format" -c $tmpfile --location -k "$URL"`
status=$?
if [ $status -eq 0 ]; then
if [ -n "$search" ]; then
grep -q "$search" $tmpfile.output
status=$?
rm -Rf $tmpfile $tmpfile.*
if [ $status -ne 0 ]; then
echo "HTTP CRITICAL: string '$search' not found on '$URL' - $output"
exit 2
else
echo "HTTP OK: $output"
fi
else
echo "HTTP OK: $output"
fi
else
rm -Rf $tmpfile $tmpfile.*
echo "WARNING: $URL did not respond properly" && exit 1
fi
rm -Rf $tmpfile $tmpfile.*
exit 0