#!/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