ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> activeperl
activeperl
Re: PERL Telnet Script problem
by Basil A. Daoust other posts by this author
Apr 25 2008 6:00AM messages near this date
PERL Telnet Script problem | Getting MIME::Lite working on Windows
You may want to run ppm to install Net::Telnet.
It is more secure to log in first as a user, then su - to root if required.
 From the prompt string you can see I had some issues dealing with 
different systems, so after getting a connection I hit enter, as HP 
tends to come back with a prompt.  Then I change the prompt so it will 
be consistent for the rest of my script.
here is a small piece of my code that used telnet, but I replaced this 
code and use ssh when possible with @results = `PLINK $systems[$i][0] $cmd`;

Its possible your only issue is move the $output variable to the line 
with the command?  I never used waitfor.

      use Net::Telnet();
      :
      next unless $t = new Net::Telnet( Prompt =>  '/[\$%#>]\s*$/', 
Timeout =>  500);
      next unless $t-> open(Host => $systems[$i][0]) or warn " ";
      next unless $t-> login(Name => $user, Password => $passwd) or warn " ";
      @results = $t-> cmd('') or warn " ";
      @results = $t-> cmd('PS1="$ "') or warn " ";
      @results = $t-> cmd($cmd) or warn " - command failed: ";
      $rc = $t-> close;
   }
   if ( $#results == -1 ) { push @{$results{$systems[$i][1]}},"Problems 
connecting to $systems[$i][1]\n"; }
   push @{$results{$systems[$i][1]}},$cmd."\n";
   push @{$results{$systems[$i][1]}},@results;
   $processed{$systems[$i][1]} = 1;
   print "@results\n";

SAQIB RAFIQUE wrote:
> 
>  Hi All,
> 
>  Please review following code.
>  there is no output against the code.
>  the script runs and prints the starting strings and nothing more.
> 
>  More over I was missing Net::Telnet module. So I downloaded it from CPAN.
>  Unzipped it , then I manually copied the Telnet.pm extracted from zip 
>  at path /usr/perl5/5.00503/Net
> 
>  Any help.
> 
>  #!/usr/bin/perl -w
>  #  A TELNET SCRIPT
>  #
>  #  REMOTE TELNET FETCH UPTIME
>  #
> 
>  #!/usr/bin/perl -w
>  print "***************************************\n";
>  print "***** A TELNET Script ******************** \n";
>  print "***************************************\n\n";
>  print "TELNET Tunnels in progress, Hold on. \n";
> 
>  use Net::Telnet;
>  $telnet = new Net::Telnet ( Timeout=>10, Errmode=>'die');
>  $telnet->open('xx.xx.xx.xx');
>  $telnet->waitfor('/login: $/i');
>  $telnet->print('root');
>  $telnet->waitfor('/Password: $/i');
>  $telnet->print('xxxxxxxxxx');
>  $telnet->waitfor('/# $/i');
>  $telnet->print('uname -a');
>  $output = $telnet->waitfor('/# $/i');
>  print $output;
> 
> 
>  -- 
>  Saqib Rafique
>  ------------------------------------------------------------------------
> 
>  _______________________________________________
>  ActivePerl mailing list
>  ActivePerl@[...].com
>  To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Thread:
Saqib Rafique
Basil A. Daoust

Privacy Policy | Email Opt-out | Feedback | Syndication
© 2004 ActiveState, a division of Sophos All rights reserved