Re: doubts in using net::telnet in perl

2010-07-22 Thread Chas. Owens
On Thu, Jul 22, 2010 at 03:38, Sooraj S  wrote:
> Thanks for your help...It worked...My shell script prints properly...
>
> At one stage it will prompt for user input
> --
> Mountpoint : Xpr23filesystem
> Kernel : verified
> P2P : katren"
> OK to go : [y/n] ?
> --
>
> How to get the user input...? (shell sctipt is called in my main code
> as shown in my first mail)
snip

If you need to interact with the shell or with programs you can use
the cmd method.  You will need to use lower level methods that let you
watch for content:

# type the command and hit enter
$t->print("$my_loc/my_shell.csh");
# wait for the program to reach the [y/n] prompt
$t->waitfor('^OK to go : \[y/n] \?');
# do this if you want it to be interactive
#my $choice = ;
#$t->print($choice);
# or you can just send the same choice every time
$t->print("y");

You will need to use the put method instead of the print method if the
program does not require you to hit enter after typing y or n.


-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: doubts in using net::telnet in perl

2010-07-22 Thread Sooraj S
Thanks for your help...It worked...My shell script prints properly...

At one stage it will prompt for user input
--
Mountpoint : Xpr23filesystem
Kernel : verified
P2P : katren"
OK to go : [y/n] ?
--

How to get the user input...? (shell sctipt is called in my main code
as shown in my first mail)


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: doubts in using net::telnet in perl

2010-07-21 Thread Chas. Owens
On Wed, Jul 21, 2010 at 10:41, Sooraj S  wrote:
> Hi Chas Owens,
>
> Thanks for your reply. I tried as you suggested. It prints the output
> in the run time but the output is unformatted.
snip
>
> Is there any way to avoid the address values that gets attached to the
> actual output..
snip

Hmm, it looks like you need $t->output_log(\*STDOUT) not $t->dump_log(\*STDOUT).


-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: doubts in using net::telnet in perl

2010-07-21 Thread Sooraj S
Hi Chas Owens,

Thanks for your reply. I tried as you suggested. It prints the output
in the run time but the output is unformatted.

< 0x0: 77 6f 72 6b  2f 61 74 6c  61 6e 74 69  63 5f 6e 6f  home/
shell_script
< 0x00010: 72 5f 72 65  6c 65 61 73  65 2e 63 73  68 5f 74 65
_newlone.csh_te
< 0x00020: 73 74 0d 0a  0d 0a 47 6f  6c 64 65 6e  20 4a 46 46
stMounted File
< 0x00030: 53 32 20 3d  20 76 65 6e  74 6c 6e 78  30 2d 6e 6f  system
= xxdper12
.
.
..


It should actually print like

home/shell_script_newlone.csh_test
Mounted Filesystem = xxdper12

Is there any way to avoid the address values that gets attached to the
actual output..


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: doubts in using net::telnet in perl

2010-07-21 Thread Chas. Owens
On Tue, Jul 20, 2010 at 10:57, Sooraj S  wrote:
> Hi,
>
> I am using Net::Telnet module to login to a remote machine and to
> perform a series of steps. In my script i am calling a shell script
> which does some operations and takes almost 3 min to complete. I want
> to redirect the output of that script to the console in run time, when
> it is running. Is there any way to do this?
>
> code
> =
> $t = new Net::Telnet(Timeout => 180, Output_log => "$my_loc/my_op");
> $t->open($my_machine);
> $t->login($username, $passwd);
> 
> 
> 
> print $t->cmd("$my_loc/my_shell.csh")     // It prints the output
> after execution.
> $t->close();

If you say

$t->dump_log(\*STDOUT); before you call $t->cmd(), then everything
that would have been written to the telnet screen will be written to
the standard output.


-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




doubts in using net::telnet in perl

2010-07-21 Thread Sooraj S
Hi,

I am using Net::Telnet module to login to a remote machine and to
perform a series of steps. In my script i am calling a shell script
which does some operations and takes almost 3 min to complete. I want
to redirect the output of that script to the console in run time, when
it is running. Is there any way to do this?

code
=
$t = new Net::Telnet(Timeout => 180, Output_log => "$my_loc/my_op");
$t->open($my_machine);
$t->login($username, $passwd);



print $t->cmd("$my_loc/my_shell.csh") // It prints the output
after execution.
$t->close();

Pls help me.


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Problem with retrieving output from commands using net::telnet

2005-12-21 Thread Stephen Kratzer
Your regexes are probably not doing what you expect them to. You're using 
character classes, so it's waiting for the device to return a one character 
prompt that matches any one of the characters from the class. Try something 
like /password[: ]*$/i and something similar for other prompts.

> All,
>
> I'm trying to write a perl script that will telnet a device and run one
> of two commands based on the output from a beginning command. I'm still
> in the beginning stages of this, and right now I'm simply trying to
> print the output from the device to standard out. Reading the
> documentation on Net::Telnet, it should be as easy as something like
> this:
>
> @lines = $t->print("who");
> print @lines;
>
> But when I try something similar, my array appears to simply contain the
> number '1', as if something were returning true.
>
> Here the full script I'm working on now (names have been changed to
> protect the innocent):
>
> #!/usr/bin/perl -w
> # $Id$
>
> use warnings;# or -w above
> use strict;
>
> use Net::Telnet;
>
> my $t = Net::Telnet->new( Timeout => 10);
> my $address = '10.10.10.1';
> my @output;
>
> #print "I'm telnetting to $address.\n";
> $t->open($address);
> print "Telnetting to  $address\n";
> $t->waitfor('/[Password:]/');
> print "Logging in\n";
> $t->print('password');
> $t->waitfor('/[hostname>]/');
> @output = $t->print('who');
> $t->waitfor('/[hostname>]/');
> $t->print('exit');
> print "Logged out\n";
> print @output;
> exit;
>
> And here's the output I'm getting:
>
> Telnetting to  10.10.10.1
> Logging in
> Logged out
> 1
>
> What's going on here? Am I doing something wrong?
>
> Tim Huffman
> Network Administrator
> Kruger Communications
> Office: 630-281-7100 ext. 335
> Fax: 630-986-2495
> Email: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Problem with retrieving output from commands using net::telnet

2005-12-20 Thread Tim Huffman
All,

I'm trying to write a perl script that will telnet a device and run one
of two commands based on the output from a beginning command. I'm still
in the beginning stages of this, and right now I'm simply trying to
print the output from the device to standard out. Reading the
documentation on Net::Telnet, it should be as easy as something like
this:

@lines = $t->print("who");
print @lines;

But when I try something similar, my array appears to simply contain the
number '1', as if something were returning true.

Here the full script I'm working on now (names have been changed to
protect the innocent):

#!/usr/bin/perl -w
# $Id$

use warnings;# or -w above
use strict;

use Net::Telnet;

my $t = Net::Telnet->new( Timeout => 10);
my $address = '10.10.10.1';
my @output;

#print "I'm telnetting to $address.\n";
$t->open($address);
print "Telnetting to  $address\n";
$t->waitfor('/[Password:]/');
print "Logging in\n";
$t->print('password');
$t->waitfor('/[hostname>]/');
@output = $t->print('who');
$t->waitfor('/[hostname>]/');
$t->print('exit');
print "Logged out\n";
print @output;
exit;

And here's the output I'm getting:

Telnetting to  10.10.10.1
Logging in
Logged out
1

What's going on here? Am I doing something wrong? 

Tim Huffman
Network Administrator
Kruger Communications
Office: 630-281-7100 ext. 335
Fax: 630-986-2495
Email: [EMAIL PROTECTED] 



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: is this an array context or scalar context?, while using Net::Telnet

2005-06-27 Thread MEENA SELVAM
hi,

i am not getting the output of the remote command
execution, in the $output, though the dump_log shows
that cmd is executed successfully,

 the following code involves scalar context or array
context?

my output ie temp array is printed as three
blanklines followed by []

i want to know in this code, the @tmp really contains
the output or 1 or the boolean status only. (in my
case it is about 30 lines)
, and i run single command(although multiple cmds are
supported in the code)

sub sfRemoteRun($$){

my $telnet = shift;
$cmds = shift;

my @results;   
my @buf;

print STDERR " -SFREMOTERUN $runtime\n" if $DEBUG;
eval {
local $SIG{'ALRM'} = sub {die "runtimedout";};
alarm $runtime;

foreach my $eachcmd (@{$cmds}){
my @tmp = $telnet->cmd("$eachcmd");
push @results, @tmp;
printf("temp array: \n");
foreach (@tmp) {
print "$_\n";
}

}

$telnet->close;
alarm 0;
};


__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: using Net::Telnet to test a http server

2002-11-25 Thread david
Admin-Stress wrote:

> Hi David,
> 
> Thanks, I followed your suggestion, and it's working fine now.
> 
> About this test, what I need is to test the http server it self, not a
> website.
> 
> I meant, in one http server, can host more than one website (name based
> virtual hosting?). So, if www.google.com and www.google.net in one http
> server, and accidently www.google.com removed, but www.google.net still
> exist, my test to www.google.com will fail ... and the http server is
> working fine.
> 
> That's why I prefer to use telnet port 80 for this purpose, by catching
> 
> 
> Any other idea?
> 

Oh, i see what you mean. i misunderstood you in your first post. sorry!
yes you are right that a http server can host multiple web sites. but your 
telnet port 80 method still won't catch it. for example, it's not strictly 
neccessary for a web server to listen to 80. 

david

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: using Net::Telnet to test a http server

2002-11-25 Thread Admin-Stress
Hi David,

Thanks, I followed your suggestion, and it's working fine now.

About this test, what I need is to test the http server it self, not a website.

I meant, in one http server, can host more than one website (name based virtual 
hosting?).
So, if www.google.com and www.google.net in one http server, and accidently 
www.google.com
removed, but www.google.net still exist, my test to www.google.com will fail ... and 
the http
server is working fine.

That's why I prefer to use telnet port 80 for this purpose, by catching 

Any other idea?

Regards,
kapot

--- david <[EMAIL PROTECTED]> wrote:
> Admin-Stress wrote:
> 
> > Hi, I wrote a script to test if a http server is OK.
> > My method is :
> > - telnet to por 80
> > - send any text
> > 
> > If the http server is OK, it will return "some" text, and should contain
> > string 
> > 
> > So, I assume, if I can catch , then my http server is OK.
> > 
> > Here is my perl script:
> > 
> >use Net::Telnet;
> > 
> >sub error {
> >  print -255;
> >  exit(0);
> >}
> > 
> >print "Testing http at $ARGV[0]\n";
> > 
> >$telnet = new Net::Telnet ( Timeout=>30, Port=>80, Errmode=>error );
> >$telnet->open($ARGV[0]);
> >$telnet->print('TESTING');
> >$telnet->waitfor('/<\/html>/');
> >print 0;
> > 
> > The problem is, it always result -255 ... sub error called.
> > However, if I set Errmode=>'die', it will result 0.
> > 
> > Anyone know how to setup Errmode with a subroutine?
> > 
> > And, is my method good for testing http server? I just want as simple as
> > possible.
> > 
> 
> Have you try changing:
> 
> Erromode=>error
> 
> to:
> 
> Errormode=>\&error
> 
> this should do the trick. However, it sounds a little odd to use the Telnet 
> module to test a http server especially there are other modules that are 
> designed to work with the http protocal. will something like:
> 
> #!/usr/bin/perl -w
> use strict;
> 
> use LWP::UserAgent;
> 
> my $agent = LWP::UserAgent->new;
> my $req = HTTP::Request->new(HEAD => 'http://www.google.com');
> my $res = $agent->request($req);
> 
> if($res->is_success){
> print "google up\n";
> }else{
> print "google down?\n";
> }
> 
> __END__
> 
> make more sense?
> 
> david


__
Do you Yahoo!?
Yahoo! Mail Plus – Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: using Net::Telnet to test a http server

2002-11-25 Thread david
Admin-Stress wrote:

> Hi, I wrote a script to test if a http server is OK.
> My method is :
> - telnet to por 80
> - send any text
> 
> If the http server is OK, it will return "some" text, and should contain
> string 
> 
> So, I assume, if I can catch , then my http server is OK.
> 
> Here is my perl script:
> 
>use Net::Telnet;
> 
>sub error {
>  print -255;
>  exit(0);
>}
> 
>print "Testing http at $ARGV[0]\n";
> 
>$telnet = new Net::Telnet ( Timeout=>30, Port=>80, Errmode=>error );
>$telnet->open($ARGV[0]);
>$telnet->print('TESTING');
>$telnet->waitfor('/<\/html>/');
>print 0;
> 
> The problem is, it always result -255 ... sub error called.
> However, if I set Errmode=>'die', it will result 0.
> 
> Anyone know how to setup Errmode with a subroutine?
> 
> And, is my method good for testing http server? I just want as simple as
> possible.
> 

Have you try changing:

Erromode=>error

to:

Errormode=>\&error

this should do the trick. However, it sounds a little odd to use the Telnet 
module to test a http server especially there are other modules that are 
designed to work with the http protocal. will something like:

#!/usr/bin/perl -w
use strict;

use LWP::UserAgent;

my $agent = LWP::UserAgent->new;
my $req = HTTP::Request->new(HEAD => 'http://www.google.com');
my $res = $agent->request($req);

if($res->is_success){
print "google up\n";
}else{
print "google down?\n";
}

__END__

make more sense?

david

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




using Net::Telnet to test a http server

2002-11-25 Thread Admin-Stress
Hi, I wrote a script to test if a http server is OK.
My method is :
- telnet to por 80
- send any text

If the http server is OK, it will return "some" text, and should contain string 

So, I assume, if I can catch , then my http server is OK.

Here is my perl script:

   use Net::Telnet;

   sub error {
 print -255;
 exit(0);
   }

   print "Testing http at $ARGV[0]\n";

   $telnet = new Net::Telnet ( Timeout=>30, Port=>80, Errmode=>error );
   $telnet->open($ARGV[0]);
   $telnet->print('TESTING');
   $telnet->waitfor('/<\/html>/');
   print 0;

The problem is, it always result -255 ... sub error called.
However, if I set Errmode=>'die', it will result 0.

Anyone know how to setup Errmode with a subroutine?

And, is my method good for testing http server? I just want as simple as possible.

Thanks,
kapot

__
Do you Yahoo!?
Yahoo! Mail Plus – Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Using Net::Telnet

2002-11-21 Thread Murali S

Hi,

I'm facing the same problem mentioned below "Pattern match read eof". Any
ideas what could be the reason?

Thanks

--
 I'm trying to use the Net::Telnet module to talk
to a port a remote machine. There is an application
on the remote machine (on a specific port) that
takes a username/group as input and returns whether
the user is a member of said group. No logging in
is done at all.
An example (done from the shell)

telnet host.domain port
Trying xxx.xxx.xxx.xxx... <- remote machine
Connect to host.domain<- remote machine
Escape character is '^]'. <- remote machine

At this point I would enter the username group combination

User Group

If it's a "1" then the user is a member of that group, 0 is not.

 Ok, now to the problem.

 A snippet of my code:

$connect = Net::Telnet->new (Port   => ,
 Timeout=> 5,
 Input_log  => "/tmp/input",
 Dump_log   => "/tmp/dump");

$connect->open(Host);

$results = $connect->cmd(Username Group); (This is line 21)

print "Results is $results\n";

 Results is not printed, and at the command line I see

pattern match read eof at ./telnet.pl line 21

 Looking at the input_log above, it contains a "1", which is
correct, because the User is a member of that group. It also
has a "0" when I've used a combination I knew that wouldn't work.

I'd like to capture the results of the command in the $results scalar
above. How do I go about and doit?

 Thanks.

P.S. Using the print() and waitfor() combination, resulted in a
timeout error. If I set the timeout, the /tmp/input file was empty.



S.Muralidhar
Software Engineer
Cisco Systems (I) Pvt Ltd.,
Ph: +91-80-2299625 Extn 3536
Res: +91-80-5702418


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Using Net::Telnet

2002-06-11 Thread Ken Hammer

Hi,

 I'm trying to use the Net::Telnet module to talk
to a port a remote machine. There is an application
on the remote machine (on a specific port) that
takes a username/group as input and returns whether
the user is a member of said group. No logging in
is done at all.
An example (done from the shell)

telnet host.domain port
Trying xxx.xxx.xxx.xxx... <- remote machine
Connect to host.domain<- remote machine
Escape character is '^]'. <- remote machine

At this point I would enter the username group combination

User Group

If it's a "1" then the user is a member of that group, 0 is not.

 Ok, now to the problem.

 A snippet of my code:

$connect = Net::Telnet->new (Port   => ,
 Timeout=> 5,
 Input_log  => "/tmp/input",
 Dump_log   => "/tmp/dump");

$connect->open(Host);

$results = $connect->cmd(Username Group); (This is line 21)

print "Results is $results\n";

 Results is not printed, and at the command line I see

pattern match read eof at ./telnet.pl line 21

 Looking at the input_log above, it contains a "1", which is 
correct, because the User is a member of that group. It also
has a "0" when I've used a combination I knew that wouldn't work.

I'd like to capture the results of the command in the $results scalar
above. How do I go about and doit?

 Thanks.

P.S. Using the print() and waitfor() combination, resulted in a
timeout error. If I set the timeout, the /tmp/input file was empty.

-- 
Ken Hammer
University Of Michigan

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]