|
|
|
@@ -21,14 +21,14 @@
|
|
|
|
################################################################################
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
|
|
|
|
# check_smhi
|
|
|
|
# check_smhi
|
|
|
|
Version="0.1"
|
|
|
|
Version="0.2"
|
|
|
|
Author="Jack-Benny Persson (jack-benny@cyberinfo.se)"
|
|
|
|
Author="Jack-Benny Persson (jack-benny@cyberinfo.se)"
|
|
|
|
|
|
|
|
|
|
|
|
# Binaries
|
|
|
|
# Binaries
|
|
|
|
Which="/usr/bin/which"
|
|
|
|
Which="/usr/bin/which"
|
|
|
|
# Binaries entered in the list will be avalible to the script as variables with
|
|
|
|
# Binaries entered in the list will be avalible to the script as variables with
|
|
|
|
# the first letter uppercase
|
|
|
|
# the first letter uppercase
|
|
|
|
Binaries=(sed awk egrep printf curl)
|
|
|
|
Binaries=(sed awk egrep printf curl head)
|
|
|
|
|
|
|
|
|
|
|
|
# Variables
|
|
|
|
# Variables
|
|
|
|
District=""
|
|
|
|
District=""
|
|
|
|
@@ -145,7 +145,7 @@ if [ $# -eq 0 ]; then
|
|
|
|
exit $State_unknown
|
|
|
|
exit $State_unknown
|
|
|
|
|
|
|
|
|
|
|
|
elif [ $# -ge 1 ]; then
|
|
|
|
elif [ $# -ge 1 ]; then
|
|
|
|
echo "$1" | egrep -q "\-."
|
|
|
|
echo "$1" | $Egrep -q "\-."
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "$0 requires an option"
|
|
|
|
echo "$0 requires an option"
|
|
|
|
print_help
|
|
|
|
print_help
|
|
|
|
@@ -184,7 +184,7 @@ Index=0
|
|
|
|
Match=0
|
|
|
|
Match=0
|
|
|
|
|
|
|
|
|
|
|
|
while [ $Index -lt $Tot ]; do
|
|
|
|
while [ $Index -lt $Tot ]; do
|
|
|
|
echo ${AvailDistricts[$Index]} | egrep -x "$District" &> /dev/null
|
|
|
|
echo ${AvailDistricts[$Index]} | $Egrep -x "$District" &> /dev/null
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
Match=1
|
|
|
|
Match=1
|
|
|
|
break
|
|
|
|
break
|
|
|
|
@@ -201,10 +201,10 @@ fi
|
|
|
|
### Main ###
|
|
|
|
### Main ###
|
|
|
|
|
|
|
|
|
|
|
|
# Fetch the warning page
|
|
|
|
# Fetch the warning page
|
|
|
|
Data=`curl -s http://www.smhi.se/vadret/vadret-i-sverige/Varningar/varning_tabell_n1_sv.htm`
|
|
|
|
Data=`$Curl -s http://www.smhi.se/vadret/vadret-i-sverige/Varningar/varning_tabell_n1_sv.htm`
|
|
|
|
|
|
|
|
|
|
|
|
# First we must replace all åäö with their HTML equivalent
|
|
|
|
# First we must replace all åäö with their HTML equivalent
|
|
|
|
HtmlDist=`echo $District | sed '{
|
|
|
|
HtmlDist=`echo $District | $Sed '{
|
|
|
|
s/å/\å\;/g
|
|
|
|
s/å/\å\;/g
|
|
|
|
s/Å/\Å\;/g
|
|
|
|
s/Å/\Å\;/g
|
|
|
|
s/ä/\ä\;/g
|
|
|
|
s/ä/\ä\;/g
|
|
|
|
@@ -214,17 +214,24 @@ s/Ö/\Ö\;/g
|
|
|
|
}'`
|
|
|
|
}'`
|
|
|
|
|
|
|
|
|
|
|
|
# Get the line number for the current district in the HTML-file and add one line to it
|
|
|
|
# Get the line number for the current district in the HTML-file and add one line to it
|
|
|
|
LineNr=`echo "$Data" | sed -n "/$HtmlDist/="`
|
|
|
|
LineNr=`echo "$Data" | $Sed -n "/$HtmlDist/=" | $Head -n1`
|
|
|
|
((LineNr++))
|
|
|
|
((LineNr++))
|
|
|
|
|
|
|
|
|
|
|
|
# Read the warning message (for example kuling, orkan, åska)
|
|
|
|
# Read the warning message (for example kuling, orkan, åska)
|
|
|
|
WarnMsg=`echo "$Data" | sed -n "${LineNr}p" | egrep -o "Varning klass [0-3] .*" | \
|
|
|
|
WarnMsg=`echo "$Data" | $Sed -n "${LineNr}p" | $Egrep -o "Varning klass [0-3] .*" | \
|
|
|
|
sed 's/\(.*\).........../\1/' | \
|
|
|
|
$Sed 's/\(.*\).........../\1/' | \
|
|
|
|
awk '{print substr($0, index($0,$4))}'`
|
|
|
|
$Awk '{print substr($0, index($0,$4))}' | $Sed '{
|
|
|
|
|
|
|
|
s/\å\;/å/g
|
|
|
|
|
|
|
|
s/\Å\;/Å/g
|
|
|
|
|
|
|
|
s/\ä\;/ä/g
|
|
|
|
|
|
|
|
s/\Ä\;/Å/g
|
|
|
|
|
|
|
|
s/\ö\;/ö/g
|
|
|
|
|
|
|
|
s/\Ö\;/Ö/g
|
|
|
|
|
|
|
|
}'`
|
|
|
|
|
|
|
|
|
|
|
|
# Get the current warning class (1, 2 and 3)
|
|
|
|
# Get the current warning class (1, 2 and 3)
|
|
|
|
Class=`echo "$Data" | sed -n "${LineNr}p" | egrep -o "Varning klass [0-3]" \
|
|
|
|
Class=`echo "$Data" | $Sed -n "${LineNr}p" | $Egrep -o "Varning klass [0-3]" \
|
|
|
|
| awk '{ print $3 }'`
|
|
|
|
| $Awk '{ print $3 }'`
|
|
|
|
|
|
|
|
|
|
|
|
# Chech the current warning class issued for the district
|
|
|
|
# Chech the current warning class issued for the district
|
|
|
|
if [ -z $Class ]; then
|
|
|
|
if [ -z $Class ]; then
|
|
|
|
|