Adding internet check to each script
This commit is contained in:
parent
50083b19a7
commit
fa881976af
|
@ -51,13 +51,25 @@ getAmount()
|
|||
fi
|
||||
}
|
||||
|
||||
checkInternet()
|
||||
{
|
||||
echo -e "GET http://google.com HTTP/1.0\n\n" | nc google.com 80 > /dev/null 2>&1
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
return 0
|
||||
else
|
||||
echo "Error: no active internet connection" >&2
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
convertCurrency()
|
||||
{
|
||||
exchangeRate=$(curl -s "http://api.fixer.io/latest?base=$base&symbols=$exchangeTo" | grep -Eo "[0-9][.][0-9]*") > /dev/null
|
||||
exchangeAmount=$(echo "$exchangeRate * $amount" | bc )
|
||||
echo "$amount $base is equal to $exchangeAmount $exchangeTo"
|
||||
}
|
||||
|
||||
checkInternet || exit 1
|
||||
getBase
|
||||
getExchangeTo
|
||||
getAmount
|
||||
|
|
|
@ -7,7 +7,7 @@ checkInternet()
|
|||
if [ $? -eq 0 ]; then
|
||||
return 0
|
||||
else
|
||||
echo "Error no active internet connection" >&2
|
||||
echo "Error: no active internet connection" >&2
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#!/bin/sh
|
||||
# Author: Alexander Epstein https://github.com/alexanderepstein
|
||||
getWeather()
|
||||
{
|
||||
country=$(curl -s ipinfo.io/country) > /dev/null
|
||||
if [ $country = "US" ];then
|
||||
city=$(curl -s ipinfo.io/city) > /dev/null
|
||||
|
@ -10,3 +12,19 @@ else
|
|||
location=$(curl -s ipinfo.io/loc) > /dev/null
|
||||
curl wttr.in/$location
|
||||
fi
|
||||
}
|
||||
|
||||
checkInternet()
|
||||
{
|
||||
echo "GET http://google.com HTTP/1.0\n\n" | nc google.com 80 > /dev/null 2>&1
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
return 0
|
||||
else
|
||||
echo "Error: no active internet connection" >&2
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
checkInternet || exit 1
|
||||
getWeather
|
||||
|
|
Loading…
Reference in New Issue