forked from alvicsam/Zabbix-web-check
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweb_check.sh
executable file
·48 lines (43 loc) · 1.4 KB
/
web_check.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
#!/bin/bash
#
#The script checks a web site and count the key word/show lines with the key work
# Usage:
# ./web_check.sh 'https://64.233.165.99/' 'Google' wc "Host:www.google.com"
# ./web_check.sh 'https://64.233.165.99/' 'Google' tail "Host:www.google.com"
# or
# ./web_check.sh 'https://ya.ru/' 'yandex' wc
# ./web_check.sh 'https://ya.ru/' 'yandex' tail
# tail - show lines with keyword
# wc - count number of keyword
URL=$1
WORD=$2
OPTION=$3
HEADER=$4
BROWSER1='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36 OPR/66.0.3515.44'
BROWSER2='Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:72.0) Gecko/20100101 Firefox/72.0'
BROWSER3='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36'
RANDOMN=`echo $(( ( RANDOM % 3 ) + 1 ))`
BROWSER="BROWSER$RANDOMN"
CURL_OPTIONS="-k -s -L -A"
if [[ $# -lt 3 ]] ; then
echo "Usage: $0 <url> <keyword> <option> [<header>]"
echo
echo "Example: $0 'https://www.google.com/' 'google' wc"
exit 0
fi
if [[ $OPTION = "wc" ]]
then
OPTION="wc -l"
elif [[ $OPTION = "tail" ]]
then
OPTION="tail -n 3"
else
echo "Option is wrong. Use either 'wc' or 'tail'"
exit 1
fi
if [[ -n $HEADER ]];
then
curl $CURL_OPTIONS "${!BROWSER}" -H "$HEADER" -L $URL | grep $WORD | $OPTION
else
curl $CURL_OPTIONS "${!BROWSER}" $URL | grep $WORD | $OPTION
fi