Linux check if server exists by IP and port

Task: Check if server exists by IP and port in the Jenkins Job before connect to it by SSH in the bash script

Solution:

server=192.168.1.1
if nc -z $server 22 2>/dev/null; then
    echo "$server Ok"
    # Do some actions....
else
    echo "$server Fail"
    # Do some actions....
fi

Done.

Leave a Reply

Your email address will not be published. Required fields are marked *

9  +  1  =  

Skynin cache:
Array ( [cache mode] => capture [requestKey] => 91b65d6cd10b8cf6f88416aaa8058aa178.sc [skycache_disable_capture] => false )