PERL Telnet Script problem

PERL Telnet Script problem

am 25.04.2008 13:57:55 von SAQIB RAFIQUE

--===============1349271008==
Content-Type: multipart/alternative;
boundary="----=_Part_1685_7616586.1209124675800"

------=_Part_1685_7616586.1209124675800
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

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

------=_Part_1685_7616586.1209124675800
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline


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

------=_Part_1685_7616586.1209124675800--

--===============1349271008==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============1349271008==--

Re: PERL Telnet Script problem

am 25.04.2008 14:59:56 von bdaoust

This is a multi-part message in MIME format.
--===============1587285658==
Content-type: multipart/alternative;
boundary=------------070209010109040503000103

This is a multi-part message in MIME format.
--------------070209010109040503000103
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

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@listserv.ActiveState.com
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


--------------070209010109040503000103
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit







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:
cite="mid:25f7c0c40804250457y56f75da9gc133a268d064ca7f@mail. gmail.com"
type="cite">

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

To unsubscribe:







--------------070209010109040503000103--


--===============1587285658==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============1587285658==--