Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re: Telnet Issue

by ramlight (Friar)
on Sep 03, 2009 at 17:47 UTC ( [id://793256] : note . print w/replies, xml ) Need Help??

in reply to Telnet Issue

Could you please repost your code surrounded with <code> tags?

It looks like you are doing

$telnet = `telnet $hostname`; $output = $telnet->waitfor('/\$ $/i');
If I read your code correctly, $telnet is the data returned from the telnet command. But you are then using it as if it were a Net::Telnet object.

Replies are listed 'Best First'.
Re^2: Telnet Issue
by jag (Initiate) on Sep 03, 2009 at 18:33 UTC
    I am reposting my code again as per your request.
    I have commented the Net::Telnet Object.
    #!/usr/bin/perl -w
    print "Enter the hostname you want to connect? \n" ;
    $hostname = <>;
    $telnet = `telnet $hostname `;
    $telnet -> waitfor('/Username: $/i');
    $telnet -> print('axiom');
    $telnet -> waitfor('/Password: $/i');
    $telnet -> print('axiom');
    $telnet -> waitfor('/\$ $/i');
    $telnet -> print('who');
    $output = $telnet->waitfor('/\$ $/i');
    print $output;
    Thanks for your response.
      As ssandy pointed out in greater detail, this is simply not going to do what you would like it to.
      $telnet = `telnet $hostname `; $telnet -> waitfor('/Username: $/i');
      If you want to script a telnet session, `telnet` isn't going to get you there; you're going to have to find another approach (such as Net::Telnet).

      Perhaps you might want to tell us more about why you decided NOT to use Net::Telnet. Perhaps someone here can help you get it to do what you need.

        Hi guys, Thanks for all your support, the reason why i didnt choose Net::Telnet is i was not having the root access to install the Net::Telnet module. Thats why i tried with this option. Cheers, Jag