-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmyCheck.sh
63 lines (47 loc) · 1.44 KB
/
myCheck.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
63
#!/bin/bash
#==================================================================================================
#title :myCheck.sh
#description :This script will parse the json using JQ, check the site connectivity and display
# the result ✔ google, ✗ mysite
#author :Sonam Maheshwari
#date :09/16/2018
#==================================================================================================
#Add permissions for jq setup file
chmod -R 777 ./jq-osx-amd64.dms
#this jq command is required to parse the json input file
jq=./jq-osx-amd64.dms
Script_Name=$0
argument=1
usage() {
echo "Please provide the input file"
echo "Usage: $Script_Name <File_Name>"
exit 1
}
if [ $# -ne $argument ];then
usage
fi
input=$1
File_Name=$(cat $input)
#this command is to fetch the site name from the json file
Site_Name=($(echo $File_Name | $jq -r '.checks.ping[].id'))
#this command is to fetch the site URL from the json file
Site_URL=($(echo $File_Name | $jq -r '.checks.ping[].value'))
n=${#Site_Name[@]}
echo ${n}
for (( i=0; i<n; i++ ))
do
echo "Print Site Name:" ${Site_Name[$i]}
for (( j=i; j<=i; j++ ))
do
echo "Print Site URL: " ${Site_URL[$j]}
Fetch_Status=$(echo ${Site_URL[$j]} | cut -d":" -f1)
echo "$Fetch_Status"
#ping $Fetch_Status > temp
ping -c 5 $Fetch_Status
if [ $? -eq 0 ]; then
echo "✔ ${Site_Name[$i]}"
else
echo "✗ ${Site_Name[$i]}"
fi
done
done