/
elf-webavail
executable file
·43 lines (35 loc) · 1.29 KB
/
elf-webavail
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
#!/bin/bash
# This script will track availability of mjsaldanha.com
logfile=~/Warehouse/.elf-webavail.log
# Erase log file
rm -f $logfile
lock=0;
while [ true ]; do
if [[ "$lock" != "0" ]]; then sleep 30; fi
lock+=1;
# Check if website is working
beg=$(date +%s);
response=$(curl -L -m 20 --write-out %{http_code} -s -o /dev/null http://mjsaldanha.com/myip);
end=$(date +%s);
taken=$(( $end - $beg ));
# If took too long
if [[ $taken > 7 ]]; then
echo "Website is laaging!" "$(date "+%H:%M:%S %d-%m-%y"). Took $taken seconds"; # Because google.com is working, but our website isnt
echo "LAAG $(date "+%H:%M:%S %d-%m-%y") took $taken seconds" >> $logfile;
continue;
fi
if [[ "$response" == "200" ]]; then
echo "OK $(date "+%H:%M:%S %d-%m-%y") took $taken seconds" >> $logfile;
continue;
fi # If not working, continue below
# Check if network is working
curl -m 5 google.com &> /dev/null;
if [[ "$?" == "0" ]]; then
echo "Website is not working!" "$(date "+%H:%M:%S %d-%m-%y"). Took $taken seconds"; # Because google.com is working, but our website isnt
echo "FAIL $(date "+%H:%M:%S %d-%m-%y") took $taken seconds" >> $logfile;
notify-send "Website is not working!";
else
echo "False alarm. Network is not working.";
echo "NETWORK $(date "+%H:%M:%S %d-%m-%y")" >> $logfile;
fi
done