forked from ET-CS/isOnline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
checker.sh
executable file
·60 lines (55 loc) · 1.91 KB
/
checker.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
!/bin/bash
# Website status checker. by ET (etcs.me)
WORKSPACE=/root
# list of websites. each website in new line. leave an empty line in the end.
LISTFILE=$WORKSPACE/websites.lst
# Send mail in case of failure to. leave an empty line in the end.
EMAILLISTFILE=$WORKSPACE/emails.lst
# Temporary dir
TEMPDIR=$WORKSPACE/cache
# `Quiet` is true when in crontab; show output when it's run manually from shell.
# Set THIS_IS_CRON=1 in the beginning of your crontab -e.
# else you will get the output to your email every time
if [ -n "$THIS_IS_CRON" ]; then QUIET=true; else QUIET=false; fi
function test {
response=$(curl --write-out %{http_code} --silent --output /dev/null $1)
filename=$( echo $1 | cut -f1 -d"/" )
if [ "$QUIET" = false ] ; then echo -n "$p "; fi
if [ $response -eq 200 ] ; then
# remove .temp file if exist
if [ -f $TEMPDIR/$filename ]; then
# website recover
if [ "$QUIET" = false ] ; then
echo -n "$response "; echo -e "\e[33m[recovering]\e[0m"
fi
while read e; do
# using mailx command
echo "$p WEBSITE UP" | mailx -s "$1 WEBSITE UP ( $response )" $e
# using mail command
#mail -s "$p WEBSITE DOWN" "$EMAIL"
done < $EMAILLISTFILE
rm -f $TEMPDIR/$filename;
else
# website working
if [ "$QUIET" = false ] ; then
echo -n "$response "; echo -e "\e[32m[ok]\e[0m"
fi
fi
else
# website down
if [ "$QUIET" = false ] ; then echo -n "$response "; echo -e "\e[31m[DOWN]\e[0m"; fi
if [ ! -f $TEMPDIR/$filename ]; then
while read e; do
# using mailx command
echo "$p WEBSITE DOWN" | mailx -s "$1 WEBSITE DOWN ( $response )" $e
# using mail command
#mail -s "$p WEBSITE DOWN" "$EMAIL"
done < $EMAILLISTFILE
echo > $TEMPDIR/$filename
fi
fi
}
# main loop
while read p; do
test $p
done < $LISTFILE