-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.sh
executable file
·62 lines (59 loc) · 1.42 KB
/
main.sh
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#! /bin/bash
while test $# -gt 0; do
case "$1" in
-h|--help)
echo "Polling endpoint for status"
echo " "
echo "./main.sh [options]"
echo " "
echo "options:"
echo "-h, --help Show brief help"
echo "--url=URL url to poll"
echo "--interval=INTERVAL Interval between each call, in seconds"
echo "--timeout=TIMEOUT Timeout before stop polling, in seconds"
exit 0
;;
--url*)
url=`echo $1 | sed -e 's/^[^=]*=//g'`
shift
;;
--code*)
code=`echo $1 | sed -e 's/^[^=]*=//g'`
shift
;;
--username*)
username=`echo $1 | sed -e 's/^[^=]*=//g'`
shift
;;
--password*)
password=`echo $1 | sed -e 's/^[^=]*=//g'`
shift
;;
--interval*)
interval=`echo $1 | sed -e 's/^[^=]*=//g'`
shift
;;
*)
break
;;
esac
done
function poll_status {
while true;
do
auth=""
if [[ "$username" != "" ]]; then
auth="-u $username:$password"
fi;
STATUS_CODE=`curl -A "Web Check" -sL --connect-timeout 3 -w "%{http_code}\n" $auth $url -o /dev/null`
echo "$(date +%H:%M:%S): The status code is $STATUS_CODE";
if [[ "$STATUS_CODE" == "200" ]]; then
echo "success";
exit 0;
break;
fi;
sleep $interval;
done
}
printf "\nPolling '${url%\?*}' every $interval seconds, until status is '200'\n"
poll_status