#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2011
    Posts
    3
    Rep Power
    0

    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.

    Thanks
    Raghunath Rao
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,480
    Rep Power
    1752
    That is not the best way to do this sort of thing - even rsh would be better, and better yet would be to use ssh.
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2011
    Posts
    3
    Rep Power
    0

    not able to resolve


    Dear simon,
    Thanks , but unfortunately you have not given any update how to proceed nor any inputs your reply does not look help full to me can you please elaborate on the solution front if you have any?.
    Thanks
    Raghu
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,480
    Rep Power
    1752
    Using either rsh or ssh gives you the ability to pass a command across to a remote host. You don't have to 'faff about' with timing issues passing across usernamea and passwords. You can configure the servers in question to allow connection without a password from a specific user account - that can be done more securely with ssh than with rsh.
    There are many sources on the web on how to configure ssh and I'd suggest you look for one, or more, of those.
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc

IMN logo majestic logo threadwatch logo seochat tools logo