Check via hostname not working

Check whether the input is either a hostname or IP address and then run the appropriate check
This commit is contained in:
Dallas 2018-01-17 16:41:53 -06:00 committed by GitHub
parent 5b9dae0e59
commit 756cc750d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -8,7 +8,17 @@ exitstatus=2 #default
endpoint=$2
name_instead=$4
regex="\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b"
IPTEST=$(echo $endpoint | egrep $regex)
if [ "$?" -eq 0 ]
then
result=$(/usr/local/sbin/ipsec statusall | grep 'ESTABLISHED' | grep $endpoint | cut -d":" -f2 | cut -d "," -f1 | sed -e 's/^[ \t]*//')||exit 3
else
hostip=$(dig +short $endpoint)
result=$(/usr/local/sbin/ipsec statusall | grep 'ESTABLISHED' | grep $hostip | cut -d":" -f2 | cut -d "," -f1 | sed -e 's/^[ \t]*//')||exit 3
fi
if [ "$name_instead" != "" ]
then
endpoint=$name_instead