I have a hostlist and there are several hosts. I want to use ssh to connect to them. I want to see whether the host is available or not by the time length of ssh takes. If it take long than 5s (which means it is not available). Then stop it, and ssh to next host. Once a host is available, then output the name of host. I previously use nmap, but the IT security told it is not allowed to install it on the desktop on campus.
for line in $HOSTS
ssh -o ConnectTimeout=5s $line true >> /dev/null
if [ $RESULT -eq 0 ]
echo $line > succeed.txt
echo $line > fail.txt
The above script is all I can do.
The problem is when it is failed, I want to redirect the error message
ssh: connect to host c28-0112-05.ad.mtu.edu port 22: No route to host
. But I still get the error message.