Is it possible to set a timeout on openssl's s_client command?

Use timeout command from GNU coreutils package.

timeout <time> <command>

Alternatively look at the first response to this archived blog post for a bash-only answer.


for the first loop: while read servername;do

timeout 2 bash -c "/dev/tcp/$servername/$Port" && echo Port open. || echo Port closed.

done

But the open ports is more dificult: timeout 1 openssl s_client -showcerts -connect $servername:$Port