I want to telnet some ips and I want to get the result of $?
immediately:
SO I tried:
while read ip; do
telnet $ip 1>/dev/null 2>&1
pkill $!
if [ "$?" -eq "1" ]; then
echo $ip >> host-ok
fi
done < file
But this is not a good idea because when a telnet connection can't be established it doesn't work. and always the out put of $? would be correct.
I want to be sure telnet is going to be established and then kill the process. So if telnet is established after that I want to echo $ip
to a file.
Any other solutions are welcome
Thank you