General
cancel
Showing results for 
Search instead for 
Did you mean: 

connect to a remote server through perlscript

Jonay
Occasional Advisor

connect to a remote server through perlscript

Hello,

try to build a perl-script that execute some commands on a remote server. I use the module NET::Telnet.

When I run my script i recieve the follow error:

[u51cf28:/home/u7514756/Scripts]# ./SysInfo.pl timed-out waiting for command prompt at ./SysInfo.pl line 22 [u51cf28:/home/u7514756/Scripts]#

bu I look at the debug files ... it seems that everything goes right :
Debug:
< 0x00000: ff fd 24 ÿý$

> 0x00000: ff fc 24 ÿü$

< 0x00000: ff fd 18 ÿý.

> 0x00000: ff fc 18 ÿü.

< 0x00000: ff fe 18 ff fd 20 ÿþ.ÿý

> 0x00000: ff fc 20 ÿü

< 0x00000: ff fe 20 ff fb 01 ff fb 03 ff fd 1f ff fd 21 ff ÿþ ÿû.ÿû.ÿý.ÿý!ÿ < 0x00010: fd 01 0d 0a 48 50 2d 55 58 20 75 39 31 63 39 61 ý...HP-UX u91c9a < 0x00020: 30 20 42 2e 31 31 2e 31 31 20 55 20 39 30 30 30 0 B.11.11 U 9000
< 0x00030: 2f 38 30 30 20 28 74 62 29 0d 0a 0d 0a /800 (tb)....

> 0x00000: ff fd 01 ff fd 03 ff fc 1f ff fc 21 ff fc 01 ÿý.ÿý.ÿü.ÿü!ÿü.

< 0x00000: ff fe 1f ff fe 21 ff fe 01 ÿþ.ÿþ!ÿþ.

< 0x00000: 6c 6f 67 69 6e 3a 20 login:

> 0x00000: 75 37 35 31 34 37 35 36 0d 0a u7514756..

< 0x00000: 75 37 35 31 34 37 35 36 0d 0a u7514756..

< 0x00000: 50 61 73 73 77 6f 72 64 3a 20 Password:

> 0x00000: 6c 75 6e 61 32 30 30 37 0d 0a pipo..

< 0x00000: 0d 0a ..

< 0x00000: 50 6c 65 61 73 65 20 77 61 69 74 2e 2e 2e 63 68 Please wait...ch < 0x00010: 65 63 6b 69 6e 67 20 66 6f 72 20 64 69 73 6b 20 ecking for disk
< 0x00020: 71 75 6f 74 61 73 0d 0a quotas..

< 0x00000: 54 45 52 4d 20 3d 20 28 68 70 29 20 TERM = (hp)

And inputfile:


HP-UX u91c9a0 B.11.11 U 9000/800 (tb)

login: u7514756
Password:
Please wait...checking for disk quotas
TERM = (hp)

Here is my script again with the extra otions:


use strict;
use Net::Telnet ();

# variables
my $t;
my $username = "u7514756";
my $passwd = "pipo";
my @lines;
chomp($username);
chomp($passwd);

#$t = Net::Telnet->new(Timeout => 30);
$t = Net::Telnet->new (Port => 23,
Timeout => 30,
Input_log => "/tmp/input_jonay",
Dump_log => "/tmp/dump_jonay");
$t->open("u91c9a0.cmc.be");
$t->login("$username", "$passwd");
$t->waitfor(String => '>');
$t->print('who');
#@lines = $t->cmd("who");
#print @lines;
[u51cf28:/home/u7514756/Scripts]#

what goes wrong ?

thanks in advance,

Jonay Herrera

3 REPLIES
James R. Ferguson
Acclaimed Contributor

Re: connect to a remote server through perlscript

Hi:

Are you sure that you are waiting for the correct response? You are waiting for a '>' in the code you posted.

Regards!

...JRF...
Jonay
Occasional Advisor

Re: connect to a remote server through perlscript

thanks for the quik answer,
But even without the waitfor option didn't work.

I have change it in "#" but even with that didn't work.

thanks anyway,


Jonay
Fat Scrape
Honored Contributor

Re: connect to a remote server through perlscript

Hi,

I modified your script in this way:

use strict;
use Net::Telnet ();

# variables
my $t;
my $username = "u7514756";
my $passwd = "pipo";
my @lines;
chomp($username);
chomp($passwd);

#$t = Net::Telnet->new(Timeout => 30);
$t = Net::Telnet->new (Port => 23,
Timeout => 30,
Input_log => "/tmp/input_jonay",
Dump_log => "/tmp/dump_jonay");
$t->open("u91c9a0.cmc.be");
$t->login("$username", "$passwd");
#$t->waitfor(String => '>');
$t->print('who');
@lines = $t->cmd("who");
print @lines;

and run correctly.

Fat