Telnet from shell and logout if log in not authenticate
Using unix shell script file I need to telnet to a IP further send a command to the telnet IP and get the response to a file with out using "expect" utility and I have achieved this by below command.
(sleep 3; echo admin; sleep 3; echo mypass; sleep 5;echo "show status-list"; sleep 5; echo "logout")|telnet 192.168.1.1 >>$telnet_result
But now if the user "name" or "password" is wrong we get "Failed login" when we try to telnet. I need to catch this for the first attempt itself and exit the telnet session immediately.
(sleep 3; echo admin; sleep 3; echo mypass; ... )|telnet 192.168.1.1 | grep "Failed" | " Need To Write Code here I guess To Exit if FAILED" | >>$telnet_result
Or else is their any other way or method so that I can get the "Failed Login" and exit the telenet session?. Please suggest.