forked from richie5um/TextBar-Recipes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SiteStatus.sh
executable file
·53 lines (43 loc) · 1.53 KB
/
SiteStatus.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
#!/bin/bash
WORKSPACE=~/scripts/isOnline
# list of websites. each website in new line. leave an empty line in the end.
# each line can have an url to test and an optional displayname:
# for example:
# http://hostname.com
# hostname.com/testme
# hostname.com:8181
# hostname.com;Pretty Display Name
LISTFILE=$WORKSPACE/websites.lst
# List of site/status
SITESTATUS=$WORKSPACE/sitestatus.txt
SITEUPCOUNT=0
SITEDOWNCOUNT=0
# Clean up file
if [ -f $SITESTATUS ]; then rm -f $SITESTATUS; fi
# main loop
while read p; do
#Load the website line into an array
IFS=';' read -ra WWW <<< "$p"
if [ ${#WWW[@]} -eq 1 ]; then
DISPLAYNAME=${WWW[0]}
else
DISPLAYNAME=${WWW[1]}
fi
response=$(/usr/bin/curl -L --referer ${WWW[0]} --user-agent "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36" --write-out %{http_code} --silent --output /dev/null ${WWW[0]})
if [ $response -eq 200 ] ; then
# Site up
# Increment counter
SITEUPCOUNT=$[SITEUPCOUNT+1]
# Add info to SITESTATUS file
echo -e "${DISPLAYNAME} : \e[32m[ok]\e[0m" >> $SITESTATUS
else
# Site Down
# Increment counter
SITEDOWNCOUNT=$[SITEDOWNCOUNT+1]
# Add info to SITESTATUS file
echo -e "${DISPLAYNAME} : \e[31m[DOWN]\e[0m" >> $SITESTATUS
fi
done <$LISTFILE
#Prepend the counts to SITESTATUS
echo -e "\e[92m●\e[39m$SITEUPCOUNT \e[91m●\e[39m$SITEDOWNCOUNT\n$(cat $SITESTATUS)" > $SITESTATUS
cat $SITESTATUS