bala_999 has asked for the wisdom of the Perl Monks concerning the following question:

HI, I wrote a piece of code for automating telnet in shell script, i want to ensure the login is successful or not. Help will be much appreciated!
(sleep 5 echo $USERNAME sleep 5 echo $PASSWORD sleep 5 )| telnet $IPADDRESS

Replies are listed 'Best First'.
Re: Return value of telnet using shell scripting
by pc88mxer (Vicar) on Jun 19, 2008 at 05:06 UTC
    The only way to tell is to scan the output of the telnet command to see if the login succeeded. You have to find something that will be printed when the login is successful but not printed when it isn't. Naturally, this will depend on what system you are accessing.

    Also, I would suggest using the Net::Telnet module to programatically exercise telnet.

Re: Return value of telnet using shell scripting
by kabeldag (Hermit) on Jun 19, 2008 at 07:46 UTC

    A good idea would be to read about BASH exit-codes and BASH Scripting if you want to do it in the BASH.
    You may however, have to cleanly exit the telnet command itself (something for you to work out yourself).

    If you want to do it in Perl, maybe you should/could read up on IO::Socket::INET and Net::Telnet.