Use nc utility for that, smth like
nc
# After hostname, the port can be specified # Let's set connection timeout to 1 sec if nc -zw1 $hostname >/dev/null 2>&1 then echo "'$hostname' is reachable!" fi