in reply to Telnet in perl

Hi

Please note the modification done on your code.

Use Net::TelNet; $telnet = new Net::Telnet ( Timeout=>3600,Prompt => "/$prompt/i",Errmo +de=>'die'); $telnet->open("susan"); $telnet->waitfor('/login: $/i'); $telnet->print('blab'); $telnet->waitfor('/password: $/i'); $telnet->print('blab'); $telnet->waitfor("/$prompt/i"); @hostname = $telnet->cmd("hostname"); print"Host Details => ", join("-",@hostname) , "\n";

"Keep pouring your ideas"

Replies are listed 'Best First'.
Re^2: Telnet in perl
by Anonymous Monk on Jun 26, 2006 at 10:18 UTC
    Hi Shmem/jesuashok,

    I tried both of yours code and got the output as follows,
    <susan@sohuswmisr:>perl 354.pl Host =>
    Expected output
    Host => susan@dohudemidt
    Pls help me monks.
    Thanks.
      Hi Ananymous Monk!

      How it will work for you.Until you give some value to the prompt it won't work at all.In the place of prompt you have to give the value what is coming when you connect manually to the remote server .

      Eg.$prompt = "\<manoj\\\@ostrich.india:\>";

      See the modified code below,
      Use Net::TelNet; $prompt = "\<manoj\\\@ostrich.india:\>"; $telnet = new Net::Telnet ( Timeout=>3600,Prompt => "/$prompt/i",Errmo +de=>'die'); $telnet->open("ostrich"); $telnet->waitfor('/login: $/i'); $telnet->print('manoj'); $telnet->waitfor('/password: $/i'); $telnet->print('manoj'); $telnet->waitfor("/$prompt/i"); print $telnet->cmd("hostname"); @hostname = $telnet->cmd("hostname"); print"Host => @hostname\n";
      See the output:-
      ostrich.india Host => ostrich.india <manoj@ostrich.india:>
      Thanks and Regards,
      madtoperl.
        Hey madtoperl,
        Lot of Thanks.Ofcousre,I never assigned the promp previously,now it is working fine.
        Thanks for your help.