-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckService.sh
More file actions
31 lines (27 loc) · 759 Bytes
/
checkService.sh
File metadata and controls
31 lines (27 loc) · 759 Bytes
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
#!/bin/bash
server=$1
port=$2
#get last status
laststatus=$(mysql -D servicestatus -sNe "select status from status where ip='$1' and port='$2' order by date desc limit 1")
echo "Last status code: "$laststatus
declare -i laststat
laststat=$laststatus
#NetCat gets server:port status 0 = OK 1 = Failed
nc -zv $server $port
x=$?
echo "Current status code: "$x
if [ $x = 0 ]
then
echo "Service working fine"
#write status 0 if previous status was 1
if [ $laststat -eq 1 ]
then
mysql -D servicestatus -e "insert into status (ip, port, status) values ('$1','$2','$x');"
fi
elif [ $x = 1 ]
then
echo "Service seems to be down"
mysql -D servicestatus -e "insert into status (ip, port, status) values ('$1','$2','$x');"
else
echo "Whaaat the fuck???"
fi