Initial commit.
This commit is contained in:
commit
eec831c560
2 changed files with 75 additions and 0 deletions
75
checkconnection.sh
Executable file
75
checkconnection.sh
Executable file
|
@ -0,0 +1,75 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
#
|
||||||
|
## Variables
|
||||||
|
#
|
||||||
|
|
||||||
|
# Testsites should return HTTP-Code "204"
|
||||||
|
testsite1=https://datenkastl.de/.connectivity-check
|
||||||
|
testsite2=http://captiveportal.kuketz.de
|
||||||
|
|
||||||
|
# Testdomains for ping
|
||||||
|
testdomain1=datenkastl.de
|
||||||
|
testdomain2=metager.de
|
||||||
|
|
||||||
|
#Path of curl and ping
|
||||||
|
curlbin=`type -tp curl`
|
||||||
|
pingbin=`type -tp ping`
|
||||||
|
|
||||||
|
#
|
||||||
|
## Functions
|
||||||
|
#
|
||||||
|
|
||||||
|
# Check connetction with curl
|
||||||
|
testwithcurl() {
|
||||||
|
echo "Testing with curl..."
|
||||||
|
|
||||||
|
status=$(curl --write-out "%{http_code}\n" "$testsite1" --output output.txt --silent)
|
||||||
|
if [[ "$status" = "204" ]]; then
|
||||||
|
echo "The connection is up!"
|
||||||
|
|
||||||
|
else
|
||||||
|
|
||||||
|
status2=$(curl --write-out "%{http_code}\n" "$testsite2" --output output.txt --silent)
|
||||||
|
if [[ "$status2" = "204" ]]; then
|
||||||
|
echo "The network is up, but $testsite1 is down."
|
||||||
|
|
||||||
|
else
|
||||||
|
echo "The network is down."
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
#Check connection with ping
|
||||||
|
testwithping() {
|
||||||
|
echo "Testing with ping..."
|
||||||
|
if ping -q -c 1 -W 1 $testdomain1 >/dev/null; then
|
||||||
|
echo "The connection is up."
|
||||||
|
|
||||||
|
elif ping -q -c 1 -W 1 $testdomain2 >/dev/null; then
|
||||||
|
echo "The network is up, but $testdomain1 is down."
|
||||||
|
|
||||||
|
else
|
||||||
|
echo "The network is down."
|
||||||
|
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
## Main
|
||||||
|
#
|
||||||
|
|
||||||
|
# Check for curl and ping and check network
|
||||||
|
|
||||||
|
if [[ -x ${curlbin} ]]; then
|
||||||
|
testwithcurl
|
||||||
|
|
||||||
|
elif [[ -x ${pingbin} ]]; then
|
||||||
|
testwithping
|
||||||
|
|
||||||
|
else
|
||||||
|
echo "Can't find curl or ping. Please install one of them."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
0
output.txt
Normal file
0
output.txt
Normal file
Loading…
Reference in a new issue