Skip to content

Instantly share code, notes, and snippets.

@toddlers
Created August 29, 2017 03:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toddlers/d297467a5570226a6a96e4cf9c75842d to your computer and use it in GitHub Desktop.
Save toddlers/d297467a5570226a6a96e4cf9c75842d to your computer and use it in GitHub Desktop.
vpn cehck
#!/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