#!/bin/bash HOST=$1 PORT=$2 timeout 1 bash -c "cat < /dev/null > /dev/tcp/${HOST}/${PORT}" RESULT=$? if [ "${RESULT}" -ne 0 ]; then echo "Failed: ${RESULT}" else echo "Connected: ${RESULT}" fi