Created
August 29, 2017 03:40
-
-
Save toddlers/d297467a5570226a6a96e4cf9c75842d to your computer and use it in GitHub Desktop.
vpn cehck
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -x | |
host="<IP_ADDRESS>" | |
port="22" | |
email="user@example.com" | |
subject="Script result" | |
if ping -i 3 -q -c 4 $host >/dev/null | |
then | |
ping_result="OK" | |
else | |
ping_result="NOT OK" | |
fi | |
nc_result=`nc -z -w5 $host $port; echo $?` | |
if [ $nc_result != 0 ]; | |
then | |
port_result="not opened" | |
else | |
port_result="opened" | |
fi | |
message="Ping to host - ${ping_result}, port $port ${port_result}." | |
if [ "$ping_result" != "OK" -o "$nc_result" != "0" ]; | |
then | |
echo "$message" | |
echo "$message" | mail -s "$subject" $email | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment