Re: Help on Net::Telnet perl module

2011-07-11 Thread John Mason Jr

On 7/9/2011 2:46 PM, Irfan Sayed wrote:

  modified the code.

   my $t = new Net::Telnet (Timeout =>  20,
Prompt =>  '/bash\$ $/',
Dump_Log   =>  $filename,
Input_log  =>  $file,
Errmode=>  $errmode,
Host =>  $host,
Input_record_separator =>  "\n",
Output_record_separator =>  "\n",
);

  $t->open("$host");
  $t->login($username, $passwd);

my @lines = $t->cmd("ls");
  print "@lines\n";
  my $ok = $t->print(@lines);
 print "$ok\n";

in this code also , i am expecting @lines should print the contents
of "ls" command
when i execute this code , it just execute without any error

but the content of @lines are NULL
the dump_log and input_log says , it has successfully connected to
remote server and executed the "ls " command but @lines does not
contain any output of "ls" command/

this is also not happening

plz suggest

I have a suspicion that your prompt is not being matched, and then you 
are timing out.


You may find that if you aren't seeing what you need to troubleshoot 
this in the logs that using wiresharrk to capture the network traffic 
might help.


http://www.wireshark.org/


John



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




Re: Help on Net::Telnet perl module

2011-07-09 Thread Irfan Sayed
 modified the code.

  my $t = new Net::Telnet (Timeout => 20,
                           Prompt => '/bash\$ $/',
                           Dump_Log   => $filename,
                           Input_log  => $file,
                           Errmode    => $errmode,
                           Host => $host,
                           Input_record_separator => "\n",
                           Output_record_separator => "\n",
);

     $t->open("$host");
     $t->login($username, $passwd);

my @lines = $t->cmd("ls");
         print "@lines\n";
     my $ok = $t->print(@lines);
    print "$ok\n";

in this code also , i am expecting @lines should print the contents 
of "ls" command
when i execute this code , it just execute without any error

but the content of @lines are NULL
the dump_log and input_log says , it has successfully connected to 
remote server and executed the "ls " command but @lines does not 
contain any output of "ls" command/

this is also not happening

plz suggest


____________
From: Jim Gibson 
To: Irfan Sayed ; beginners@perl.org
Sent: Saturday, July 9, 2011 4:08 AM
Subject: Re: Help on Net::Telnet perl module




 You chose to allow Jim Gibson (jimsgib...@gmail.com) even though this message 
failed authentication 
Click to disallow 

Re: Help on Net::Telnet perl module

2011-07-08 Thread Jim Gibson
On 7/8/11 Fri  Jul 8, 2011  12:43 PM, "Irfan Sayed"
 scribbled:

> here is the actual code
> 
> 
> use Net::Telnet;
> $telnet = new Net::Telnet ( Timeout=>10, Errmode=>'die');
> $telnet->open('10.216.119.53');
> $telnet->waitfor('/login: $/i');
> $telnet->print('abc');
> $telnet->waitfor('/password: $/i');
> $telnet->print('xyz');
> $telnet->waitfor('/\$ $/i');
> $telnet->print('ls');
> $output = $telnet->waitfor('/\$ $/i');
> print $output;
> 
> 
> now, what i expect is, programme shud print the content of $output on the
> console 
> 
> the $output shud have the value of the result of "ls" command
> 
> plz suggest 

Please read the documentation for Net::Telnet, which says that the print
function returns 1 if all data was successfully written. If you wish to
capture the output from a command executed on the telnet server, use the
cmd() function and assign the function return to an array, not a scalar:

my @output = $telnet->cmd('ls');
print @output;




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




Re: Help on Net::Telnet perl module

2011-07-08 Thread Irfan Sayed
i have written my own code and i am printing dump_log and input_log as well
in the log , it says , everything is successful, i am getting the output of 
"ls" command as well.in the log


but on the console it is not printing the output 


plz suggest

regards
irfan




From: Jim Gibson 
To: Perl Beginners 
Sent: Friday, July 8, 2011 10:47 PM
Subject: Re: Help on Net::Telnet perl module




 You chose to allow Jim Gibson (jimsgib...@gmail.com) even though this message 
failed authentication 
Click to disallow 

Re: Help on Net::Telnet perl module

2011-07-08 Thread Jim Gibson
On 7/8/11 Fri  Jul 8, 2011  5:59 AM, "Irfan Sayed"
 scribbled:

> hi,
> 
> i am using Net::Telnet module to connect to remote hosts
> i able to to successfully connect to remote host and run the "ls" command
> but the issue is , the output of command is not getting printed to scalar
> variable 
> 
> 
> use Net::Telnet ();
> $t = new Net::Telnet (Timeout => 10,
> Prompt => '/bash\$ $/');
> $t->open("abc");
> $t->login($username, $passwd);
> @lines = $t->cmd("ls");
> print @lines;

That looks like the sample code included with 'perldoc Net::Telnet'. That
presumes that you have assigned valid values to the $username and $passwd
variables. Have you?

You have no error checking in your code. Since you are apparently getting an
error, it is time to add some error checking. See 'perldoc Net::Telnet' for
how to do this. The documentation recommends the use of input_log() and
dump_log() to trace the data sent back and forth between your program and
the telnet server.

Unfortunately, I cannot find a telnet server to test your program. Most
telnet access has been replaced by ssh these days.



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




Help on Net::Telnet perl module

2011-07-08 Thread Irfan Sayed
hi,

i am using Net::Telnet module to connect to remote hosts 
i able to to successfully connect to remote host and run the "ls" command 
but the issue is , the output of command is not getting printed to scalar 
variable 


use Net::Telnet ();
$t = new Net::Telnet (Timeout => 10,
Prompt => '/bash\$ $/');
$t->open("abc");
$t->login($username, $passwd);
@lines = $t->cmd("ls");
print @lines;

please suggest.

regards,
irfan

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: Problems with "show tech" using the Net::Telnet Module

2010-04-25 Thread Uri Guttman
> "A" == Asterix   writes:


  A> Instead of this printf OUTPUT_FILE "@output\n\n";
  A> I've used   print OUTPUT_FILE "@output\n\n";

that would not make any difference in buffering or anything. the second
is better in that you don't use printf's formatting there. when i see
lots of printf calls, i know the coder was doing too much c before they
learned perl. printf is actually rarely needed in perl. sprintf is more
useful when you need formatting since you can decide where/when to write
the output later.


  A> At the top of the script I also inserted "Autoflush":
  A> local $| = 1; # Default is 0

no need for local there. $| is private to the currently selected output
handle.

uri

-- 
Uri Guttman  --  u...@stemsystems.com    http://www.sysarch.com --
-  Perl Code Review , Architecture, Development, Training, Support --
-  Gourmet Hot Cocoa Mix    http://bestfriendscocoa.com -

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




Re: Problems with "show tech" using the Net::Telnet Module

2010-04-25 Thread Asterix
On 20 Apr, 12:25, t.baetz...@bringe.com (Thomas Bätzler) wrote:
> Asterix asked:
>
> > I've made a little script to capture the output of networking
> > devices.
> > Everything works fine, until I use the "show tech" command in an Cisco
> > device.
>
> Have you considered using the cmd() method of Net::Telnet? It has the option 
> to individually set a reply timeout for each command:
>
> #!/usr/bin/perl-w
>
> use strict;
> use Net::Telnet;
>
> my $host = '42.42.42.42';
> my $sysname = 'cisco';
> my $login_pw = 'letmein';
> my $enable_pw = 'secret';
>
> my $tn = Net::Telnet->new( Host => $host ) ){
> $tn->waitfor( '/word: $/' );
> $tn->cmd( String => $login_pw, Prompt => "/$sysname>\$/" );
> $tn->cmd( String => 'enable', Prompt => '/word: $/' );
> $tn->prompt( "/$sysname#\$/" );
> $tn->cmd( String => $enable_pw );
> $tn->cmd( String => 'terminal length 0' );
> my @data = $tn->cmd( String => 'show tech', Timeout => 60 );
> print @data;
>
> __END__
>
> Works fine for me on a 7206. YMMV.
>
> HTH,
> Thomas

===

Thank you for your response !
I've figured out the problem. It was not a problem regarding TELNET
but regarding the flushing of the Buffer (Filehadle, STDOUT):


Instead of this printf OUTPUT_FILE "@output\n\n";
I've used   print OUTPUT_FILE "@output\n\n";


At the top of the script I also inserted "Autoflush":
local $| = 1; # Default is 0


http://perldoc.perl.org/perlvar.html


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




Re: Problems with "show tech" using the Net::Telnet Module

2010-04-25 Thread Asterix
On 20 Apr, 12:25, t.baetz...@bringe.com (Thomas Bätzler) wrote:
> Asterix asked:
>
> > I've made a little script to capture the output of networking
> > devices.
> > Everything works fine, until I use the "show tech" command in an Cisco
> > device.
>
> Have you considered using the cmd() method of Net::Telnet? It has the option 
> to individually set a reply timeout for each command:
>
> #!/usr/bin/perl-w
>
> use strict;
> use Net::Telnet;
>
> my $host = '42.42.42.42';
> my $sysname = 'cisco';
> my $login_pw = 'letmein';
> my $enable_pw = 'secret';
>
> my $tn = Net::Telnet->new( Host => $host ) ){
> $tn->waitfor( '/word: $/' );
> $tn->cmd( String => $login_pw, Prompt => "/$sysname>\$/" );
> $tn->cmd( String => 'enable', Prompt => '/word: $/' );
> $tn->prompt( "/$sysname#\$/" );
> $tn->cmd( String => $enable_pw );
> $tn->cmd( String => 'terminal length 0' );
> my @data = $tn->cmd( String => 'show tech', Timeout => 60 );
> print @data;
>
> __END__
>
> Works fine for me on a 7206. YMMV.
>
> HTH,
> Thomas

Thank you for your response !
I've figured out the problem. It was not a problem regarding TELNET
but regarding the flushing of the Buffer (Filebuffer, STDOUT).


Instead of this printf OUTPUT_FILE "@output\n\n";
I've usedprint OUTPUT_FILE "@output\n\n";


At the top of the script I also inserted "Autoflush":
local $| = 1; # Default is 0


http://perldoc.perl.org/perlvar.html



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




AW: Problems with "show tech" using the Net::Telnet Module

2010-04-20 Thread Thomas Bätzler
Asterix  asked:
> I've made a little script to capture the output of networking
> devices.
> Everything works fine, until I use the "show tech" command in an Cisco
> device.

Have you considered using the cmd() method of Net::Telnet? It has the option to 
individually set a reply timeout for each command:

#!/usr/bin/perl -w

use strict;
use Net::Telnet;

my $host = '42.42.42.42';
my $sysname = 'cisco';
my $login_pw = 'letmein';
my $enable_pw = 'secret';

my $tn = Net::Telnet->new( Host => $host ) ){
$tn->waitfor( '/word: $/' );
$tn->cmd( String => $login_pw, Prompt => "/$sysname>\$/" );
$tn->cmd( String => 'enable', Prompt => '/word: $/' );
$tn->prompt( "/$sysname#\$/" );
$tn->cmd( String => $enable_pw );
$tn->cmd( String => 'terminal length 0' );
my @data = $tn->cmd( String => 'show tech', Timeout => 60 );
print @data;

__END__

Works fine for me on a 7206. YMMV.

HTH,
Thomas

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




Problems with "show tech" using the Net::Telnet Module

2010-04-20 Thread Asterix
I've made a little script to capture the output of networking
devices.
Everything works fine, until I use the "show tech" command in an Cisco
device.
The script does not save anything form the "show tech",
but I can see that the TELNET Session gets back some output.
But I can't figure out how to save this output from "show tech" into a
file.
There is no problem with commands which produce smaller output.
I don't want to use the "Net::Telnet:Cisco" Module:

Here is the part, that does not work the way I want:

 #!/usr/bin/perl
# Autor:Ing. Gerhard Hermann Lange
# Date: 12/04/2010
# Description:  Script for doing a TELNET to a CISCO devices and
executing some comands.
#   Long outputs from the TELNET Session (-> show 
tech) is not
possible
#       due to the TELNET session timeout of 5 seconds
use Net::Telnet;
#
my $prg_name = $0; $prg_name =~ s|^.*[\\/]||;
# Usage:
my $usage="Syntax: $prg_name
\n";
if (! defined ($ARGV[0])) { print "$usage"; exit; }
#
$SIG{'INT'} = sub {
# Subprocedure for finishing all the work
# printf OUTPUT_FILE "@output\n\n";
close(OUTPUT_FILE);
print STDERR "Termination of program ... !\n";
exit;
};
#
$hostname = $ARGV[0];
$ip = $ARGV[1];
$username = $ARGV[2];
$password = $ARGV[3];
$enpwd = $ARGV[4];
$cmd_file = "cmds.txt";
#
my ($sec, $min, $hr, $mday, $mon, $year, @etc) = localtime(time);
$mon++; $year=$year+1900;
my $now=sprintf("%.4d%.2d%.2d%.2d%.2d", $year, $mon, $mday, $min,
$sec);
my $today=sprintf("%.2d/%.2d/%.4d", $mday, $mon, $year );
#
# $out_file=$ip;
$out_file=$ip."_$now".".cfg";
#
# For debugging the TELNET Session: uncomment this line !
# $filename="telnet_dump.txt";
#
$errmode='return'; # Default: 'die'
#
# Set cmd_remove_mode to the number of lines to remove (0 in this
case).
# http://www.perlmonks.org/?node_id=736670
$errmode="return";
$telnet = new Net::Telnet ( Timeout=>5, Errmode=>$errmode ,
cmd_remove_mode => '0', Dump_Log =>
$filename);

# $telnet = new Net::Telnet ( Timeout=>3, Errmode=>$errmode ,
Output_record_separator => "\r",cmd_remove_mode => '2', Dump_Log =>
$filename);
# -output_record_separator => "\r");
$telnet->open($ip);
#
$telnet->waitfor('/Username: $/i');
$telnet->print($username);
$telnet->waitfor('/Password: $/i');
$telnet->print($password);
#
# Wait for the prompt, send "enable" and enable-pwd
@output = $telnet->waitfor('/>/');
$telnet->print('enable');
$telnet->waitfor('/Password:/i');
$telnet->print($enpwd);
#
@output = $telnet->waitfor('/#/i');
#
open(OUTPUT_FILE, ">>$out_file");
printf OUTPUT_FILE "IP Address: $ip\n";
printf OUTPUT_FILE "Hostname:   $hostname\n";
printf OUTPUT_FILE "Data:   $today\n";
printf OUTPUT_FILE "\n";
#
# Creat an universal Prompt for this hostname
my $prompt = $hostname."#";
$telnet->prompt("/$prompt\$/");
@output = $telnet->cmd(String => "terminal length 0");
printf OUTPUT_FILE "@output\n\n";
#
open(CMDFILE, "<$cmd_file");
while (my $record = ) {
if ($record !~ /^(#|!|\s)/) {
chomp($record);
my @record_array = (split(/;/,$record));
my $command = $record_array[0]; chomp($cmd);
#
$telnet->prompt("/$prompt\$/");
@output = $telnet->cmd(String => "$command", Timeout=>30);
#
printf OUTPUT_FILE "@output\n\n";
}
}
# Close the command File for this device
close(CMDFILE);
#
$telnet->print('exit');
close(OUTPUT_FILE);


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




RE: Feeding ouput from Net::Telnet into sub

2010-04-10 Thread Joseph L. Casale
>so it could still likely use a review. especially if you are learning
>perl. many doc examples aren't written to the best coding standards.

I'll take you up on that once its "supposedly" done:)

Many great tips, thanks for all the help!
jlc

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




Re: Feeding ouput from Net::Telnet into sub

2010-04-10 Thread Uri Guttman
> "JLC" == Joseph L Casale  writes:

  >> nothing HAS to be global. you can pass it to a sub, you can store the
  >> options in a hash (my way and easy with getopt::long), etc. some globals
  >> may be useful but always using them or not know other ways is bad.

  JLC> Ok, fair enough.

that is true for all programming, not just perl.

  JLC> Well the rest of the code _only_ does the telnet part and has too much
  JLC> hardcoded stuff atm. It works perfectly as per cpan docs.

so it could still likely use a review. especially if you are learning
perl. many doc examples aren't written to the best coding standards.

  JLC> I think I have it:

  JLC> sub parse_output {
  JLC> my ( $string, $match ) = @_;

better.
  JLC> die "Error in parse_output sub\n" unless ((defined $string) || 
(defined $match));

don't put the \n in the die string so it will report the line number
too. and your boolean test is wrong. you want both to be defined. and
even defined is overkill if you know you have text and a match
string. unless either is just '' or '0' they will be true. so that line
can be:

die "Error in parse_output sub" unless $string && $match ;

  JLC> if ( $string =~ /$match/ ) {
  JLC> return "OK";
  JLC> } else {
  JLC> return "CRITICAL";
  JLC> }

that is a very odd indent style. the returns should be indented the
same. the }else and close should be left indented one more. like this:

if ( $string =~ /$match/ ) {
return "OK";
}
else {
return "CRITICAL";
}


  JLC> $status = parse_output($output, $expect);
  JLC> print "Status: $status\n";

  >>> From what I can see, this follows all the suggestions you have provided?

and there are more! always more. :)

uri

-- 
Uri Guttman  --  u...@stemsystems.com    http://www.sysarch.com --
-  Perl Code Review , Architecture, Development, Training, Support --
-  Gourmet Hot Cocoa Mix    http://bestfriendscocoa.com -

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




RE: Feeding ouput from Net::Telnet into sub

2010-04-10 Thread Joseph L. Casale
>nothing HAS to be global. you can pass it to a sub, you can store the
>options in a hash (my way and easy with getopt::long), etc. some globals
>may be useful but always using them or not know other ways is bad.

Ok, fair enough.

>no. it is a single string with 4 lines in it. why would you think
>foreach would loop over its lines vs its single string? arrays can
>contain strings without lines and a scalar could contain a single string
>with lines. so foreach is neutral and just loops over what you pass it
>in terms of perl elements. if you want lines, split them yourself or get
>them some other way. e.g. backticks in a list context will split its
>output into lines for you. i dunno how you are doing this telnet thing
>(as i said SHOW MORE/ALL CODE :).

Well the rest of the code _only_ does the telnet part and has too much
hardcoded stuff atm. It works perfectly as per cpan docs.

I'm just stuck on formatting the sub to match a string, just don't know
enough about Perl:)

I think I have it:

sub parse_output {
my ( $string, $match ) = @_;
die "Error in parse_output sub\n" unless ((defined $string) || (defined 
$match));
if ( $string =~ /$match/ ) {
return "OK";
} else {
return "CRITICAL";
}
}

$status = parse_output($output, $expect);
print "Status: $status\n";

>From what I can see, this follows all the suggestions you have provided?
Thanks for all your help!
jlc

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




Re: Feeding ouput from Net::Telnet into sub

2010-04-10 Thread Uri Guttman
> "JLC" == Joseph L Casale  writes:

  >> use a named variable with foreach loops. sure some docs and examples
  >> show using the default $_ but it can have problems with action at a
  >> distance. also a name makes the code read better.

  JLC> Ok, simple enough to do.

  >> and where does $match get set? it must be from outside the sub so it is
  >> a global. bad!

  JLC> Well $match comes from Getopt::Long, it has to be global, no? Now I'm 
confused:)

nothing HAS to be global. you can pass it to a sub, you can store the
options in a hash (my way and easy with getopt::long), etc. some globals
may be useful but always using them or not know other ways is bad.

  >> same with status. either declare it locally and return it or do
  >> something else but don't set globals just to mark something as ok

  JLC> Soon after posting I realized it was cleaner to return the value...

  >> more code and data. use Data::Dumper to show exactly what you are
  >> passing in.

  JLC> I used Data::Dumper to see what was actually being passed and it takes
  JLC> the following form:

  JLC> $VAR1 = 'system status
  JLC>system status: Normal

  JLC> hostname';

  JLC> Sorry for the noobish question, but I am not sure how to interpret this?
  JLC> I assumed this was 4 lines of text, but I guess not?

no. it is a single string with 4 lines in it. why would you think
foreach would loop over its lines vs its single string? arrays can
contain strings without lines and a scalar could contain a single string
with lines. so foreach is neutral and just loops over what you pass it
in terms of perl elements. if you want lines, split them yourself or get
them some other way. e.g. backticks in a list context will split its
output into lines for you. i dunno how you are doing this telnet thing
(as i said SHOW MORE/ALL CODE :).

uri

-- 
Uri Guttman  --  u...@stemsystems.com    http://www.sysarch.com --
-  Perl Code Review , Architecture, Development, Training, Support --
-  Gourmet Hot Cocoa Mix    http://bestfriendscocoa.com -

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




RE: Feeding ouput from Net::Telnet into sub

2010-04-10 Thread Joseph L. Casale
>use a named variable with foreach loops. sure some docs and examples
>show using the default $_ but it can have problems with action at a
>distance. also a name makes the code read better.

Ok, simple enough to do.

>and where does $match get set? it must be from outside the sub so it is
>a global. bad!

Well $match comes from Getopt::Long, it has to be global, no? Now I'm confused:)

>same with status. either declare it locally and return it or do
>something else but don't set globals just to mark something as ok

Soon after posting I realized it was cleaner to return the value...

>more code and data. use Data::Dumper to show exactly what you are
>passing in.

I used Data::Dumper to see what was actually being passed and it takes
the following form:

$VAR1 = 'system status
   system status: Normal

hostname';

Sorry for the noobish question, but I am not sure how to interpret this?
I assumed this was 4 lines of text, but I guess not?

Thanks for the help!
jlc

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




Re: Feeding ouput from Net::Telnet into sub

2010-04-10 Thread Uri Guttman
>>>>> "JLC" == Joseph L Casale  writes:

  JLC> I get a page full of output from a command passed into a
  JLC> Net::Telnet session that as per the cpan example is stored in
  JLC> $output. I then want to call a sub passing $output into it, that
  JLC> matches a string against each line, and sets a a var to "OK" if
  JLC> the match is successful.

  JLC> All is well, but I am unclear on the correct way to loop through
  JLC> each line in $output, when I simply print it, it appears over
  JLC> several lines in the terminal.

  JLC> When I run it into my sub, its being treated as one line?

you need to show how you call this sub and its input. there is no way to
diagnose it from just this code.

  JLC> sub parse_output {
  JLC> foreach (@_) {

use a named variable with foreach loops. sure some docs and examples
show using the default $_ but it can have problems with action at a
distance. also a name makes the code read better.

  JLC> chomp($_);

if you do use $_, there is no need to pass it to many ops including
chomp. chomp by itself does the same thing.

  JLC> print "Line: $_\n";
  JLC> if ( $_ =~ /$match/ ) {

again, m// will match against $_ so either don't bind to it or bind to a
named variable (or some expression).

and where does $match get set? it must be from outside the sub so it is
a global. bad!

  JLC> $status = "OK";

same with status. either declare it locally and return it or do
something else but don't set globals just to mark something as ok

  JLC> next;
  JLC> }
  JLC> }
  JLC> }

  JLC> parse_output($output);

  JLC> It only prints one "Line:" although it works as it sets $status?

works in what way? if i pass it one line with something that matches, it
will pass that 'test'.

  JLC> What am I missing?

more code and data. use Data::Dumper to show exactly what you are
passing in.

uri

-- 
Uri Guttman  --  u...@stemsystems.com    http://www.sysarch.com --
-  Perl Code Review , Architecture, Development, Training, Support --
-  Gourmet Hot Cocoa Mix    http://bestfriendscocoa.com -

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




Feeding ouput from Net::Telnet into sub

2010-04-10 Thread Joseph L. Casale
I get a page full of output from a command passed into a Net::Telnet session
that as per the cpan example is stored in $output. I then want to call a sub
passing $output into it, that matches a string against each line, and sets a
a var to "OK" if the match is successful.

All is well, but I am unclear on the correct way to loop through each line in
$output, when I simply print it, it appears over several lines in the terminal.

When I run it into my sub, its being treated as one line?

sub parse_output {
foreach (@_) {
chomp($_);
print "Line: $_\n";
if ( $_ =~ /$match/ ) {
$status = "OK";
next;
}
}
}

parse_output($output);

It only prints one "Line:" although it works as it sets $status?

What am I missing?
Thanks!
jlc




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




SSH equivalent to Net::Telnet::Cisco?

2008-10-07 Thread Paul
I've searched CPAN, but have not found an equivalent module such as
Net::Telnet::Cisco for SSH (SSH2).  Is there one somewhere out there? 
Thanks.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: SSH equivalent to Net::Telnet::Cisco?

2008-10-06 Thread Rodrick Brown
Have you tried the standard Net::SSH does it not work with cisco devices?

On Mon, Oct 6, 2008 at 1:22 PM, Paul <[EMAIL PROTECTED]> wrote:

> I've searched CPAN, but have not found an equivalent module such as
> Net::Telnet::Cisco for SSH (SSH2).  Is there one somewhere out there?
> Thanks.
>
>
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> http://learn.perl.org/
>
>
>


-- 
[ Rodrick R. Brown ]
http://www.rodrickbrown.com http://www.linkedin.com/in/rodrickbrown


SSH equivalent to Net::Telnet::Cisco?

2008-10-06 Thread Paul
I've searched CPAN, but have not found an equivalent module such as
Net::Telnet::Cisco for SSH (SSH2).  Is there one somewhere out there? 
Thanks.




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Net::Telnet "pattern match timed-out..."

2008-09-17 Thread ariel . casas
Hello all,
I am trying to automate a simple telnet to port 7010 and give me the
output to the command "gstatus".  However, I get the following error:


./telnet_mod.test.pl
pattern match timed-out at ./telnet_mod.test.pl line 6

Here are the contents of the script:
---
#!/usr/bin/perl -w
use Net::Telnet ;
$t = new Net::Telnet (Timeout => 10) ;
$t->open(Host => "129.145.155.9",
 Port => "7010") ;
$t->waitfor('/Escape/') ;
$t->cmd('gstatus') ;
---


...and this is what I am trying to automate:

---
telnet 129.145.155.9 7010
Trying 129.145.155.9...
Connected to hostname.domain.com
Escape character is '^]'.

gstatus 
---


I've tried so many things, and nothing works.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Net::Telnet

2008-08-13 Thread Hashmat Khan

> >>> I get this error:
> >>> maximum input buffer length exceeded: 1048576 bytes at D:\Docs\Perl
> >>> \scripts\
> >>> ti_p2k_bld.pl line 33
>
> >>> This could be because $prematch is gets a very big string and so it
> >>> exceeds the limit which I had suspected before.
> >>> Bottomline, I want to get the $match value. How can I do this ?
>
> >> Please try to remember to bottom-post your responses to this group.
> >> Thanks again.
>
> >> You can disable the timeout by specifying a value of undef, for instance
>
> >> my $t = new Net::Telnet (Timeout => undef);
>
> >> You can't use waitfor like that. Regular expressions must be passed as
> >> strings like '/Build completed on/' but I think it's neater to use the
> >> string option like this
>
> >>   my ($prematch, $match) = $t->waitfor(
> >>     String => 'Build completed on',
> >>     String => 'Build failed on',
> >>   );
>
> > ok...thanks.
>
> > what do you mean by bottom-post the response ?
> > I am having one new problem,
>
> > when I use this: @lines = $t->cmd($bldcmd) ($prematch, $match) =
> > $t->waitfor(Match => /Build completed on/ || / Build failed on/); I get
> > this error:
> > maximum *input buffer length exceeded*: 1048576 bytes at D:\Docs\Perl
> > \scripts\
> > ti_p2k_bld.pl line 33
>

That's fine, but the actual problem is this:

$t = new Net::Telnet (Timeout => 0xF, # very high value
  #Prompt => $prompt,
  Dump_Log   => "dump_log.txt",
  Output_log => "dump_out.txt",
  Input_log  => \*STDOUT)
 later
$ok = $t->cmd(String => $bldcmd);

This command is a build command, and it takes long time to build.
Maybe half to one hour. And it outputs the files compiled, linked etc.
So the output is very huge and that is the reason it complains
maximum input buffer length exceeded: 1048576 bytes at D:\Docs\Perl
\scripts\ti_p2k_bld.pl line 33. How do I avoid this without increasing
the input buffer size ?

thanks
Hashmat


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Net::Telnet

2008-08-11 Thread Rob Dixon
Hashmat Khan wrote:
> On Mon, Aug 11, 2008 at 9:00 PM, Rob Dixon <[EMAIL PROTECTED] <mailto:[EMAIL 
> PROTECTED]>> wrote:
>> Hashmat Khan wrote:
>>>
>>> For the timeout, I used a very large value, so its solved !
>>>
>>> One more issue, when I use this:
>>>
>>>  @lines = $t->cmd($bldcmd)
>>>  ($prematch, $match) = $t->waitfor(Match => /Build completed on/ || /
>>> Build failed on/);
>>>
>>> I get this error:
>>> maximum input buffer length exceeded: 1048576 bytes at D:\Docs\Perl
>>> \scripts\
>>> ti_p2k_bld.pl line 33
>>>
>>> This could be because $prematch is gets a very big string and so it
>>> exceeds the limit which I had suspected before.
>>> Bottomline, I want to get the $match value. How can I do this ?
>> 
>> Please try to remember to bottom-post your responses to this group.
>> Thanks again.
>> 
>> You can disable the timeout by specifying a value of undef, for instance
>> 
>> my $t = new Net::Telnet (Timeout => undef);
>> 
>> You can't use waitfor like that. Regular expressions must be passed as
>> strings like '/Build completed on/' but I think it's neater to use the 
>> string option like this
>> 
>>   my ($prematch, $match) = $t->waitfor(
>> String => 'Build completed on',
>> String => 'Build failed on',
>>   );
> 
> ok...thanks.
> 
> what do you mean by bottom-post the response ?
> I am having one new problem,
> 
> when I use this: @lines = $t->cmd($bldcmd) ($prematch, $match) =
> $t->waitfor(Match => /Build completed on/ || / Build failed on/); I get
> this error:
> maximum *input buffer length exceeded*: 1048576 bytes at D:\Docs\Perl
> \scripts\
> ti_p2k_bld.pl line 33

Please keep your posts to the newsgroup rather than messaging me privately so
that others may help and learn from your questions. Thank you.

Bottom-posting means to put your response after the message you are quoting

  http://en.wikipedia.org/wiki/Bottom-posting#Bottom-posting

The waitfor method of Net::Telnet saves all data from the host until it finds
one of the conditions you specify in the call. If you have made a mistake in
specifying the conditions (which you have, as I explained in my previous post)
and disabled timeouts then data will be stored indefinitely without returning
from the call.

Without seeing your application I can't really tell, but it may be better to try
something like

  $t->waitfor(String => "\n")

and examine the build log line by line in your own code.

HTH,

Rob



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Net::Telnet

2008-08-11 Thread Rob Dixon
Hashmat Khan wrote:
> 
> For the timeout, I used a very large value, so its solved !
> 
> One more issue, when I use this:
> 
>  @lines = $t->cmd($bldcmd)
>  ($prematch, $match) = $t->waitfor(Match => /Build completed on/ || /
> Build failed on/);
> 
> I get this error:
> maximum input buffer length exceeded: 1048576 bytes at D:\Docs\Perl
> \scripts\
> ti_p2k_bld.pl line 33
> 
> This could be because $prematch is gets a very big string and so it
> exceeds the limit which I had suspected before.
> Bottomline, I want to get the $match value. How can I do this ?

Please try to remember to bottom-post your responses to this group. Thanks 
again.

You can disable the timeout by specifying a value of undef, for instance

  my $t = new Net::Telnet (Timeout => undef);

You can't use waitfor like that. Regular expressions must be passed as strings
like '/Build completed on/' but I think it's neater to use the string option
like this

  my ($prematch, $match) = $t->waitfor(
String => 'Build completed on',
String => 'Build failed on',
  );



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Net::Telnet

2008-08-11 Thread Hashmat Khan
Hello All,

For the timeout, I used a very large value, so its solved !

One more issue, when I use this:

 @lines = $t->cmd($bldcmd)
 ($prematch, $match) = $t->waitfor(Match => /Build completed on/ || /
Build failed on/);

I get this error:
maximum input buffer length exceeded: 1048576 bytes at D:\Docs\Perl
\scripts\
ti_p2k_bld.pl line 33

This could be because $prematch is gets a very big string and so it
exceeds the limit which I had suspected before.
Bottomline, I want to get the $match value. How can I do this ?

thanks,
Hashmat

On Aug 7, 7:08 pm, [EMAIL PROTECTED] (Hashmat Khan) wrote:
> Hi,
>
> The only issue I have now is with timeout, and how do I disable this ?
>
> thanks,
> Hashmat
>
> On Thu, Aug 7, 2008 at 7:07 PM, Rob Dixon <[EMAIL PROTECTED]> wrote:
> > Hashmat Khan wrote:
>
> > > ok.. the latest on this...
> > > when I try cmd for certain commands, it doesn't work.
> > > But looks like print works, but I don't see any output(Input_log  =>
> > > \*STDOUT). So I can't verify my commands in print. How do we print the
> > > output of print ?
>
> > Please try to remember to bottom-post your response to this group. Thanks.
>
> > You need to enable the output log as well, either as Output_log option for
> > the
> > constructor method, or using the output_log method after construction.
>
> > HTH,
>
> > Rob


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Net::Telnet

2008-08-07 Thread Hashmat Khan
Hi,

The only issue I have now is with timeout, and how do I disable this ?

thanks,
Hashmat

On Thu, Aug 7, 2008 at 7:07 PM, Rob Dixon <[EMAIL PROTECTED]> wrote:

> Hashmat Khan wrote:
> >
> > ok.. the latest on this...
> > when I try cmd for certain commands, it doesn't work.
> > But looks like print works, but I don't see any output(Input_log  =>
> > \*STDOUT). So I can't verify my commands in print. How do we print the
> > output of print ?
>
> Please try to remember to bottom-post your response to this group. Thanks.
>
> You need to enable the output log as well, either as Output_log option for
> the
> constructor method, or using the output_log method after construction.
>
> HTH,
>
> Rob
>


Re: Net::Telnet

2008-08-07 Thread Hashmat Khan
ok, finally I got it ! cmd works, actually I had to remove the Prompt
from the object creation, because some of the commands change the
prompt and that is why it was timing out.

Anyway, I have one last problem now, 'Timeout' , by default the value
is 10 seconds, How do I get rid of it ? The perl documentation says:
If $secs is 0 then time-out occurs if the data cannot be immediately
read or written. Use the undefined value to turn off timing-out
completely.

What is undefined value ?

Thanks,
Hashmat

On Aug 5, 2:52 pm, [EMAIL PROTECTED] (Hashmat Khan) wrote:
> Hello Rob,
>
> Thanks for the reply.
> Yes, I am using  Net::Telnet. And I am new to perl, I was not aware if there
> are other methods to start telnet using perl.
> I did as you suggested. It worked but not completely as I wanted the output.
>     use Net::Telnet ();
>     $t = new Net::Telnet (Timeout => 10,
>                           Prompt => $prompt,
>                   Dump_Log   => \*STDOUT);
>
> What is this \* used for ? Previoulsy I tried with only STDOUT and it hadn't
> worked.
>
> Basically I am looking for an output that would come as if for example I had
> used windows telnet to login to some server.
> In this output, first I see hex output too. Secondly, I don't see the prompt
> after executing each command. Thirdly, I don't see the output for the
> commands, like I used 'ls'. And I am using:
>  $t->print("ls");  I am not using cmd as it timeout for some of the
> commands.
>
> So I want to print all the input provided in the script and all the output.
>
> Thanks,
> Hashmat
>
> On Tue, Aug 5, 2008 at 4:57 AM, Rob Dixon <[EMAIL PROTECTED]> wrote:
> > Hashmat Khan wrote:
>
> > > Has anybody used Telnet ?
>
> > > I want to know, how can we redirect the output to STDOUT instead of
> > > log file ? (Dump_Log   => "dump.txt")
>
> > It's important to tell us exactly what module you're using. Telnet is a
> > comms
> > protocol but I don't  think you mean that. There is no Perl module called
> > Telnet
> > but there are many with Telnet in the name. I assume you're using
> > Net::Telnet as
> > it has a Dump_Log parameter to the constructor method, but it would have
> > been
> > much better if you'd said so.
>
> > I haven't used the module, but the documentation says that the dump_log
> > method
> > will accept an open file handle as well as a file name so
>
> >  $object->dump_log(\*STDOUT);
>
> > should work. It should also be OK to put it as a parameter to the
> > constructor as in
>
> >  my $object = Net::Telnet->new(Dump_Log => \*STDOUT);
>
> > if you'd rather do it like that. Give it a try and see.
>
> > HTH,
>
> > Rob


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Net::Telnet

2008-08-07 Thread Hashmat Khan
On Aug 5, 2:52 pm, [EMAIL PROTECTED] (Hashmat Khan) wrote:
> Hello Rob,
>
> Thanks for the reply.
> Yes, I am using  Net::Telnet. And I am new to perl, I was not aware if there
> are other methods to start telnet using perl.
> I did as you suggested. It worked but not completely as I wanted the output.
>     use Net::Telnet ();
>     $t = new Net::Telnet (Timeout => 10,
>                           Prompt => $prompt,
>                   Dump_Log   => \*STDOUT);
>
> What is this \* used for ? Previoulsy I tried with only STDOUT and it hadn't
> worked.
>
> Basically I am looking for an output that would come as if for example I had
> used windows telnet to login to some server.
> In this output, first I see hex output too. Secondly, I don't see the prompt
> after executing each command. Thirdly, I don't see the output for the
> commands, like I used 'ls'. And I am using:
>  $t->print("ls");  I am not using cmd as it timeout for some of the
> commands.
>
> So I want to print all the input provided in the script and all the output.
>
> Thanks,
> Hashmat
>
> On Tue, Aug 5, 2008 at 4:57 AM, Rob Dixon <[EMAIL PROTECTED]> wrote:
> > Hashmat Khan wrote:
>
> > > Has anybody used Telnet ?
>
> > > I want to know, how can we redirect the output to STDOUT instead of
> > > log file ? (Dump_Log   => "dump.txt")
>
> > It's important to tell us exactly what module you're using. Telnet is a
> > comms
> > protocol but I don't  think you mean that. There is no Perl module called
> > Telnet
> > but there are many with Telnet in the name. I assume you're using
> > Net::Telnet as
> > it has a Dump_Log parameter to the constructor method, but it would have
> > been
> > much better if you'd said so.
>
> > I haven't used the module, but the documentation says that the dump_log
> > method
> > will accept an open file handle as well as a file name so
>
> >  $object->dump_log(\*STDOUT);
>
> > should work. It should also be OK to put it as a parameter to the
> > constructor as in
>
> >  my $object = Net::Telnet->new(Dump_Log => \*STDOUT);
>
> > if you'd rather do it like that. Give it a try and see.
>
> > HTH,
>
> > Rob

Hello All,

I didn't see the above postings so far. I was just checking for
emails.
Anyways, now this is my script:

$t = new Net::Telnet (Timeout => 10,
  Prompt => $prompt,
  Dump_Log   => \*STDOUT)

   $t->open($hostname);
$t->login($username, $passwd)

 @lines = $t->cmd("whoami");
$t->print("ls");
## Set view
@lines = $t->print("cleartool setview $view");
 print @lines;

## change to $$$ dir
@lines = $t->print("cd $newdir");
print @lines;

## start build
[EMAIL PROTECTED] = $t->print($bldcmd);

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

 I do see the output now, but I see hex characters along with the
output. I want in the output as if I started a telnet from windows
machine using windows telnet.
I don't see the prompt changing and I don't see the output for ls. Any
reasons?

thanks,
Hashmat


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Net::Telnet

2008-08-07 Thread Hashmat Khan
And when I use print, it doesn't work, I don't see any output, but if
I use I see the output, but it times out(command timed out). thanks.

On Aug 5, 2:52 pm, [EMAIL PROTECTED] (Hashmat Khan) wrote:
> Hello Rob,
>
> Thanks for the reply.
> Yes, I am using  Net::Telnet. And I am new to perl, I was not aware if there
> are other methods to start telnet using perl.
> I did as you suggested. It worked but not completely as I wanted the output.
>     use Net::Telnet ();
>     $t = new Net::Telnet (Timeout => 10,
>                           Prompt => $prompt,
>                   Dump_Log   => \*STDOUT);
>
> What is this \* used for ? Previoulsy I tried with only STDOUT and it hadn't
> worked.
>
> Basically I am looking for an output that would come as if for example I had
> used windows telnet to login to some server.
> In this output, first I see hex output too. Secondly, I don't see the prompt
> after executing each command. Thirdly, I don't see the output for the
> commands, like I used 'ls'. And I am using:
>  $t->print("ls");  I am not using cmd as it timeout for some of the
> commands.
>
> So I want to print all the input provided in the script and all the output.
>
> Thanks,
> Hashmat
>
> On Tue, Aug 5, 2008 at 4:57 AM, Rob Dixon <[EMAIL PROTECTED]> wrote:
> > Hashmat Khan wrote:
>
> > > Has anybody used Telnet ?
>
> > > I want to know, how can we redirect the output to STDOUT instead of
> > > log file ? (Dump_Log   => "dump.txt")
>
> > It's important to tell us exactly what module you're using. Telnet is a
> > comms
> > protocol but I don't  think you mean that. There is no Perl module called
> > Telnet
> > but there are many with Telnet in the name. I assume you're using
> > Net::Telnet as
> > it has a Dump_Log parameter to the constructor method, but it would have
> > been
> > much better if you'd said so.
>
> > I haven't used the module, but the documentation says that the dump_log
> > method
> > will accept an open file handle as well as a file name so
>
> >  $object->dump_log(\*STDOUT);
>
> > should work. It should also be OK to put it as a parameter to the
> > constructor as in
>
> >  my $object = Net::Telnet->new(Dump_Log => \*STDOUT);
>
> > if you'd rather do it like that. Give it a try and see.
>
> > HTH,
>
> > Rob


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Net::Telnet

2008-08-07 Thread Hashmat Khan
ok. I figured out that giving
  Input_log  => \*STDOUT
works and it gives the correct output as desired. But the $t->cmd()
doesn't work for certain commands. Like for ls, whoami it works, but
for certain commands which change the command prompt, it doesn't work,
like setting a clearcase view, anybody has any idea ? thanks.

On Aug 5, 2:52 pm, [EMAIL PROTECTED] (Hashmat Khan) wrote:
> Hello Rob,
>
> Thanks for the reply.
> Yes, I am using  Net::Telnet. And I am new to perl, I was not aware if there
> are other methods to start telnet using perl.
> I did as you suggested. It worked but not completely as I wanted the output.
>     use Net::Telnet ();
>     $t = new Net::Telnet (Timeout => 10,
>                           Prompt => $prompt,
>                   Dump_Log   => \*STDOUT);
>
> What is this \* used for ? Previoulsy I tried with only STDOUT and it hadn't
> worked.
>
> Basically I am looking for an output that would come as if for example I had
> used windows telnet to login to some server.
> In this output, first I see hex output too. Secondly, I don't see the prompt
> after executing each command. Thirdly, I don't see the output for the
> commands, like I used 'ls'. And I am using:
>  $t->print("ls");  I am not using cmd as it timeout for some of the
> commands.
>
> So I want to print all the input provided in the script and all the output.
>
> Thanks,
> Hashmat
>
> On Tue, Aug 5, 2008 at 4:57 AM, Rob Dixon <[EMAIL PROTECTED]> wrote:
> > Hashmat Khan wrote:
>
> > > Has anybody used Telnet ?
>
> > > I want to know, how can we redirect the output to STDOUT instead of
> > > log file ? (Dump_Log   => "dump.txt")
>
> > It's important to tell us exactly what module you're using. Telnet is a
> > comms
> > protocol but I don't  think you mean that. There is no Perl module called
> > Telnet
> > but there are many with Telnet in the name. I assume you're using
> > Net::Telnet as
> > it has a Dump_Log parameter to the constructor method, but it would have
> > been
> > much better if you'd said so.
>
> > I haven't used the module, but the documentation says that the dump_log
> > method
> > will accept an open file handle as well as a file name so
>
> >  $object->dump_log(\*STDOUT);
>
> > should work. It should also be OK to put it as a parameter to the
> > constructor as in
>
> >  my $object = Net::Telnet->new(Dump_Log => \*STDOUT);
>
> > if you'd rather do it like that. Give it a try and see.
>
> > HTH,
>
> > Rob


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Net::Telnet

2008-08-07 Thread Rob Dixon
Hashmat Khan wrote:
>
> ok.. the latest on this...
> when I try cmd for certain commands, it doesn't work.
> But looks like print works, but I don't see any output(Input_log  =>
> \*STDOUT). So I can't verify my commands in print. How do we print the
> output of print ?

Please try to remember to bottom-post your response to this group. Thanks.

You need to enable the output log as well, either as Output_log option for the
constructor method, or using the output_log method after construction.

HTH,

Rob

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Net::Telnet

2008-08-07 Thread Hashmat Khan
ok.. the latest on this...
when I try cmd for certain commands, it doesn't work.
But looks like print works, but I don't see any output(Input_log  =>
\*STDOUT). So I can't verify my commands in print. How do we print the
output of print ?

On Aug 5, 2:52 pm, [EMAIL PROTECTED] (Hashmat Khan) wrote:
> Hello Rob,
>
> Thanks for the reply.
> Yes, I am using  Net::Telnet. And I am new to perl, I was not aware if there
> are other methods to start telnet using perl.
> I did as you suggested. It worked but not completely as I wanted the output.
>     use Net::Telnet ();
>     $t = new Net::Telnet (Timeout => 10,
>                           Prompt => $prompt,
>                   Dump_Log   => \*STDOUT);
>
> What is this \* used for ? Previoulsy I tried with only STDOUT and it hadn't
> worked.
>
> Basically I am looking for an output that would come as if for example I had
> used windows telnet to login to some server.
> In this output, first I see hex output too. Secondly, I don't see the prompt
> after executing each command. Thirdly, I don't see the output for the
> commands, like I used 'ls'. And I am using:
>  $t->print("ls");  I am not using cmd as it timeout for some of the
> commands.
>
> So I want to print all the input provided in the script and all the output.
>
> Thanks,
> Hashmat
>
> On Tue, Aug 5, 2008 at 4:57 AM, Rob Dixon <[EMAIL PROTECTED]> wrote:
> > Hashmat Khan wrote:
>
> > > Has anybody used Telnet ?
>
> > > I want to know, how can we redirect the output to STDOUT instead of
> > > log file ? (Dump_Log   => "dump.txt")
>
> > It's important to tell us exactly what module you're using. Telnet is a
> > comms
> > protocol but I don't  think you mean that. There is no Perl module called
> > Telnet
> > but there are many with Telnet in the name. I assume you're using
> > Net::Telnet as
> > it has a Dump_Log parameter to the constructor method, but it would have
> > been
> > much better if you'd said so.
>
> > I haven't used the module, but the documentation says that the dump_log
> > method
> > will accept an open file handle as well as a file name so
>
> >  $object->dump_log(\*STDOUT);
>
> > should work. It should also be OK to put it as a parameter to the
> > constructor as in
>
> >  my $object = Net::Telnet->new(Dump_Log => \*STDOUT);
>
> > if you'd rather do it like that. Give it a try and see.
>
> > HTH,
>
> > Rob


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Net::Telnet

2008-08-05 Thread Hashmat Khan
Hello Rob,

Thanks for the reply.
Yes, I am using  Net::Telnet. And I am new to perl, I was not aware if there
are other methods to start telnet using perl.
I did as you suggested. It worked but not completely as I wanted the output.
use Net::Telnet ();
$t = new Net::Telnet (Timeout => 10,
  Prompt => $prompt,
  Dump_Log   => \*STDOUT);

What is this \* used for ? Previoulsy I tried with only STDOUT and it hadn't
worked.

Basically I am looking for an output that would come as if for example I had
used windows telnet to login to some server.
In this output, first I see hex output too. Secondly, I don't see the prompt
after executing each command. Thirdly, I don't see the output for the
commands, like I used 'ls'. And I am using:
 $t->print("ls");  I am not using cmd as it timeout for some of the
commands.

So I want to print all the input provided in the script and all the output.

Thanks,
Hashmat

On Tue, Aug 5, 2008 at 4:57 AM, Rob Dixon <[EMAIL PROTECTED]> wrote:

> Hashmat Khan wrote:
> >
> > Has anybody used Telnet ?
> >
> > I want to know, how can we redirect the output to STDOUT instead of
> > log file ? (Dump_Log   => "dump.txt")
>
> It's important to tell us exactly what module you're using. Telnet is a
> comms
> protocol but I don't  think you mean that. There is no Perl module called
> Telnet
> but there are many with Telnet in the name. I assume you're using
> Net::Telnet as
> it has a Dump_Log parameter to the constructor method, but it would have
> been
> much better if you'd said so.
>
> I haven't used the module, but the documentation says that the dump_log
> method
> will accept an open file handle as well as a file name so
>
>  $object->dump_log(\*STDOUT);
>
> should work. It should also be OK to put it as a parameter to the
> constructor as in
>
>  my $object = Net::Telnet->new(Dump_Log => \*STDOUT);
>
> if you'd rather do it like that. Give it a try and see.
>
> HTH,
>
> Rob
>


Re: Net::Telnet

2008-08-04 Thread aditya
Hi,
If I am getting you right means you want to display on Console.
for that use this.
---CODE---
my $telnet = Net::Telnet->new(HOST);
 $telnet->login(USER,PASS)
 my @display = $telnet ->cmd('ls -l');
 print @display;
--Code--


On Aug 4, 7:47 am, [EMAIL PROTECTED] (Hashmat Khan) wrote:
> Hi,
>
> Has anybody used Telnet ?
>
> I want to know, how can we redirect the output to STDOUT instead of
> log file ? (Dump_Log   => "dump.txt")
>
> thanks,
> Hashmat


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Net::Telnet

2008-08-04 Thread aditya
Hi Hashmat,
If I am getting you correclty then use this:

CODE-
$telnet = Net::Telnet->new(HOST);
$telnet->login(USER,PASS)
@display = $telnet ->cmd('ls -l');
print @display;
CODE

On Aug 4, 11:33 am, [EMAIL PROTECTED] (Jm) wrote:
> IO::Tee allows STDOUT as one of your output options
>
>
>
>
>
> On Mon, Aug 4, 2008 at 9:47 AM, Hashmat Khan <[EMAIL PROTECTED]> wrote:
> > Hi,
>
> > Has anybody used Telnet ?
>
> > I want to know, how can we redirect the output to STDOUT instead of
> > log file ? (Dump_Log   => "dump.txt")
>
> > thanks,
> > Hashmat
>
> > --
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >http://learn.perl.org/
>
> --
> since this is a gmail account, please verify the mailing list is
> included in the reply to addresses- Hide quoted text -
>
> - Show quoted text -


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Net::Telnet

2008-08-04 Thread Rob Dixon
John W. Krahn wrote:
> Rob Dixon wrote:
>> Hashmat Khan wrote:
>>> Has anybody used Telnet ?
>>>
>>> I want to know, how can we redirect the output to STDOUT instead of
>>> log file ? (Dump_Log   => "dump.txt")
>> It's important to tell us exactly what module you're using.
> 
> See the Subject line.  :-)

Ah :$

Thanks John.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Net::Telnet

2008-08-04 Thread John W. Krahn

Rob Dixon wrote:

Hashmat Khan wrote:

Has anybody used Telnet ?

I want to know, how can we redirect the output to STDOUT instead of
log file ? (Dump_Log   => "dump.txt")


It's important to tell us exactly what module you're using.


See the Subject line.  :-)


John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.-- Larry Wall

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Net::Telnet

2008-08-04 Thread Rob Dixon
Hashmat Khan wrote:
> 
> Has anybody used Telnet ?
> 
> I want to know, how can we redirect the output to STDOUT instead of
> log file ? (Dump_Log   => "dump.txt")

It's important to tell us exactly what module you're using. Telnet is a comms
protocol but I don't  think you mean that. There is no Perl module called Telnet
but there are many with Telnet in the name. I assume you're using Net::Telnet as
it has a Dump_Log parameter to the constructor method, but it would have been
much better if you'd said so.

I haven't used the module, but the documentation says that the dump_log method
will accept an open file handle as well as a file name so

  $object->dump_log(\*STDOUT);

should work. It should also be OK to put it as a parameter to the constructor 
as in

  my $object = Net::Telnet->new(Dump_Log => \*STDOUT);

if you'd rather do it like that. Give it a try and see.

HTH,

Rob

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Net::Telnet

2008-08-04 Thread jm
IO::Tee allows STDOUT as one of your output options


On Mon, Aug 4, 2008 at 9:47 AM, Hashmat Khan <[EMAIL PROTECTED]> wrote:
> Hi,
>
> Has anybody used Telnet ?
>
> I want to know, how can we redirect the output to STDOUT instead of
> log file ? (Dump_Log   => "dump.txt")
>
> thanks,
> Hashmat
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> http://learn.perl.org/
>
>
>



-- 
since this is a gmail account, please verify the mailing list is
included in the reply to addresses

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Net::Telnet

2008-08-04 Thread Hashmat Khan
Hi,

Has anybody used Telnet ?

I want to know, how can we redirect the output to STDOUT instead of
log file ? (Dump_Log   => "dump.txt")

thanks,
Hashmat


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Prompt in Net::Telnet

2007-06-13 Thread Chas Owens

On 6/13/07, Lakshmi Sailaja <[EMAIL PROTECTED]> wrote:
snip

The reason that I am asking this is that I will have to call one more exe
(similar to ls, obtained from free-ware) for my Perl program and that is not
running either?

snip

Chances are good you are talking about Cygwin which is Free Software
not freeware*.  You will need to provide the full path to the
executable like this:

$telnet->cmd('c:\cygwin\bin\ls.exe -l > lsop.log');

* see "Comparison with other terms" on http://en.wikipedia.org/wiki/Freeware

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




RE: Prompt in Net::Telnet

2007-06-13 Thread Lakshmi Sailaja
The telnet server running on my windows machine is the Microsoft telnet
server (which comes from windows).

As suggested when I used 'dir', I am able to see the content in lsop.log.
'ls' is an exe that is obtained with some free-ware software. But I don't
see any output if I use 'ls'. But isn't there a way to get the output from
ls???

The reason that I am asking this is that I will have to call one more exe
(similar to ls, obtained from free-ware) for my Perl program and that is not
running either?

Thanks & Regards,
Lakshmi
952-833-1220

-Original Message-
From: Chas Owens [mailto:[EMAIL PROTECTED]
Sent: Wednesday, June 13, 2007 12:35 PM
To: [EMAIL PROTECTED]
Cc: beginners@perl.org
Subject: Re: Prompt in Net::Telnet


On 6/13/07, Lakshmi Sailaja <[EMAIL PROTECTED]> wrote:
> You are right that I am trying to connect to a Windows m/c from a Solaris
> server.
>
> But when I used the below code, it gets connected but I am having problem
> displaying the output:
>
>
>  my $telnet = Net::Telnet->new(HOST => "$server",
> Dump_log => "telnetdump.txt",
> PROMPT => '/[>]/');
>  $telnet->login('user', 'pass');
>  $telnet->cmd('ls -l >lsop.log');
>
> after running this program, lsop.log is being created but I don't see
> anything in it.
>
> If I can display the output, I am all good. Please suggest!!!
>
> Thanks in Advance.
>
> Regards,
> Lakshmi
> 952-833-1220

Try using

$telnet->cmd('dir > lsop.log');

There is no ls command in DOS.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Prompt in Net::Telnet

2007-06-13 Thread Chas Owens

On 6/13/07, Lakshmi Sailaja <[EMAIL PROTECTED]> wrote:

You are right that I am trying to connect to a Windows m/c from a Solaris
server.

But when I used the below code, it gets connected but I am having problem
displaying the output:


 my $telnet = Net::Telnet->new(HOST => "$server",
Dump_log => "telnetdump.txt",
PROMPT => '/[>]/');
 $telnet->login('user', 'pass');
 $telnet->cmd('ls -l >lsop.log');

after running this program, lsop.log is being created but I don't see
anything in it.

If I can display the output, I am all good. Please suggest!!!

Thanks in Advance.

Regards,
Lakshmi
952-833-1220


Try using

$telnet->cmd('dir > lsop.log');

There is no ls command in DOS.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Prompt in Net::Telnet

2007-06-13 Thread Martin Barth
i didnt understand you right, i fear, but if your server is a windows, are you 
shure that you can execute ls there?


On Wed, 13 Jun 2007 12:30:00 -0500
"Lakshmi Sailaja" <[EMAIL PROTECTED]> wrote:

> You are right that I am trying to connect to a Windows m/c from a Solaris
> server.
> 
> But when I used the below code, it gets connected but I am having problem
> displaying the output:
> 
> 
>  my $telnet = Net::Telnet->new(HOST => "$server",
> Dump_log => "telnetdump.txt",
> PROMPT => '/[>]/');
>  $telnet->login('user', 'pass');
>  $telnet->cmd('ls -l >lsop.log');
> 
> after running this program, lsop.log is being created but I don't see
> anything in it.
> 
> If I can display the output, I am all good. Please suggest!!!
> 
> Thanks in Advance.
> 
> Regards,
> Lakshmi
> 952-833-1220
> 
> -Original Message-
> From: Chas Owens [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, June 12, 2007 6:41 PM
> To: [EMAIL PROTECTED]
> Cc: beginners@perl.org
> Subject: Re: Prompt in Net::Telnet
> 
> 
> On 6/12/07, Lakshmi Sailaja <[EMAIL PROTECTED]> wrote:
> > Hello,
> >
> > I am supposed to write a program that will telnet to a remote server and
> > execute some commands. I get the following error:
> > "timed-out waiting for command prompt at  line "
> >
> > This is because the prompt is not set correctly. Can you please tell me
> what
> > the prompt value should be set to?
> >
> > how can I determine my remote machines prompt?
> >
> > Thanks in advance!!
> >
> > Regards,
> > Sailaja
> >
> >
> > --
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> > http://learn.perl.org/
> >
> >
> >
> 
> If you are trying to connect to the "telnet" server that comes with
> Microsoft OSes then you are SOL.  If you are trying to connect to a
> different telnet server, then please provide the name of the server
> and operating system it is running under so we can duplicate your
> environment.
> 
> from Perldoc Net::Telnet
>Connecting to a Remote MS-Windows Machine
> 
>By default MS-Windows doesn't come with a TELNET server.  However
> third
>party TELNET servers are available.  Unfortunately many of these
>servers falsely claim to be a TELNET server.  This is especially true
>of the so-called "Microsoft Telnet Server" that comes installed with
>some newer versions MS-Windows.
> 
>When a TELNET server first accepts a connection, it must use the
> ASCII
>control characters carriage-return and line-feed to start a new line
>(see RFC854).  A server like the "Microsoft Telnet Server" that
> doesn't
>do this, isn't a TELNET server.  These servers send ANSI terminal
>escape sequences to position to a column on a subsequent line and to
>even position while writing characters that are adjacent to each
> other.
>Worse, when sending output these servers resend previously sent
> command
>output in a misguided attempt to display an entire terminal screen.
> 
>Connecting Net::Telnet to one of these false TELNET servers makes
> your
>job of parsing command output very difficult.  It's better to replace
> a
>false TELNET server with a real TELNET server.  The better TELNET
>servers for MS-Windows allow you to avoid the ANSI escapes by turning
>off something some of them call console mode.
> 
> 
> 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




RE: Prompt in Net::Telnet

2007-06-13 Thread Lakshmi Sailaja
You are right that I am trying to connect to a Windows m/c from a Solaris
server.

But when I used the below code, it gets connected but I am having problem
displaying the output:


 my $telnet = Net::Telnet->new(HOST => "$server",
Dump_log => "telnetdump.txt",
PROMPT => '/[>]/');
 $telnet->login('user', 'pass');
 $telnet->cmd('ls -l >lsop.log');

after running this program, lsop.log is being created but I don't see
anything in it.

If I can display the output, I am all good. Please suggest!!!

Thanks in Advance.

Regards,
Lakshmi
952-833-1220

-Original Message-
From: Chas Owens [mailto:[EMAIL PROTECTED]
Sent: Tuesday, June 12, 2007 6:41 PM
To: [EMAIL PROTECTED]
Cc: beginners@perl.org
Subject: Re: Prompt in Net::Telnet


On 6/12/07, Lakshmi Sailaja <[EMAIL PROTECTED]> wrote:
> Hello,
>
> I am supposed to write a program that will telnet to a remote server and
> execute some commands. I get the following error:
> "timed-out waiting for command prompt at  line "
>
> This is because the prompt is not set correctly. Can you please tell me
what
> the prompt value should be set to?
>
> how can I determine my remote machines prompt?
>
> Thanks in advance!!
>
> Regards,
> Sailaja
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> http://learn.perl.org/
>
>
>

If you are trying to connect to the "telnet" server that comes with
Microsoft OSes then you are SOL.  If you are trying to connect to a
different telnet server, then please provide the name of the server
and operating system it is running under so we can duplicate your
environment.

from Perldoc Net::Telnet
   Connecting to a Remote MS-Windows Machine

   By default MS-Windows doesn't come with a TELNET server.  However
third
   party TELNET servers are available.  Unfortunately many of these
   servers falsely claim to be a TELNET server.  This is especially true
   of the so-called "Microsoft Telnet Server" that comes installed with
   some newer versions MS-Windows.

   When a TELNET server first accepts a connection, it must use the
ASCII
   control characters carriage-return and line-feed to start a new line
   (see RFC854).  A server like the "Microsoft Telnet Server" that
doesn't
   do this, isn't a TELNET server.  These servers send ANSI terminal
   escape sequences to position to a column on a subsequent line and to
   even position while writing characters that are adjacent to each
other.
   Worse, when sending output these servers resend previously sent
command
   output in a misguided attempt to display an entire terminal screen.

   Connecting Net::Telnet to one of these false TELNET servers makes
your
   job of parsing command output very difficult.  It's better to replace
a
   false TELNET server with a real TELNET server.  The better TELNET
   servers for MS-Windows allow you to avoid the ANSI escapes by turning
   off something some of them call console mode.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Prompt in Net::Telnet

2007-06-12 Thread Chas Owens

On 6/12/07, Chas Owens <[EMAIL PROTECTED]> wrote:
snip

If you are trying to connect to the "telnet" server that comes with
Microsoft OSes then you are SOL.  If you are trying to connect to a
different telnet server, then please provide the name of the server
and operating system it is running under so we can duplicate your
environment.

snip

Oh, yeah, you probably should bother installing a new telnet server.
Telnet is not a secure protocol and should not be used for new code.
Install OpenSSH instead.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Prompt in Net::Telnet

2007-06-12 Thread Chas Owens

On 6/12/07, Lakshmi Sailaja <[EMAIL PROTECTED]> wrote:

Hello,

I am supposed to write a program that will telnet to a remote server and
execute some commands. I get the following error:
"timed-out waiting for command prompt at  line "

This is because the prompt is not set correctly. Can you please tell me what
the prompt value should be set to?

how can I determine my remote machines prompt?

Thanks in advance!!

Regards,
Sailaja


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/





If you are trying to connect to the "telnet" server that comes with
Microsoft OSes then you are SOL.  If you are trying to connect to a
different telnet server, then please provide the name of the server
and operating system it is running under so we can duplicate your
environment.

from Perldoc Net::Telnet
  Connecting to a Remote MS-Windows Machine

  By default MS-Windows doesn't come with a TELNET server.  However third
  party TELNET servers are available.  Unfortunately many of these
  servers falsely claim to be a TELNET server.  This is especially true
  of the so-called "Microsoft Telnet Server" that comes installed with
  some newer versions MS-Windows.

  When a TELNET server first accepts a connection, it must use the ASCII
  control characters carriage-return and line-feed to start a new line
  (see RFC854).  A server like the "Microsoft Telnet Server" that doesn't
  do this, isn't a TELNET server.  These servers send ANSI terminal
  escape sequences to position to a column on a subsequent line and to
  even position while writing characters that are adjacent to each other.
  Worse, when sending output these servers resend previously sent command
  output in a misguided attempt to display an entire terminal screen.

  Connecting Net::Telnet to one of these false TELNET servers makes your
  job of parsing command output very difficult.  It's better to replace a
  false TELNET server with a real TELNET server.  The better TELNET
  servers for MS-Windows allow you to avoid the ANSI escapes by turning
  off something some of them call console mode.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Net::Telnet - Variable in Prompt

2007-06-12 Thread Chas Owens

On 6/12/07, Lakshmi Sailaja <[EMAIL PROTECTED]> wrote:
snip

$sub = "xyz";
$prompt = "L:\\$sub";

my $t = Net::Telnet->new(
Timeout => 10,
Prompt  => "/$prompt/"
);


snip

from perldoc Net::Telnet
  What To Know Before Using

  · When constructing the match operator argument for "prompt()" or
"waitfor()", always use single quotes instead of double quotes to
avoid unexpected backslash interpretation (e.g. '/bash\$ $/').  If
you're constructing a DOS like file path, you'll need to use four
backslashes to represent one (e.g. '/c:usersbill>$/i').

Of course don't forget about regexp metacharacters like ".", "[", or
"$".  You'll only need a single backslash to quote them.  The anchor
metacharacters "^" and "$" refer to positions in the input buffer.
To avoid matching characters read that look like a prompt, it's a
good idea to end your prompt pattern with the "$" anchor.  That way
the prompt will only match if it's the last thing read

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Prompt in Net::Telnet

2007-06-12 Thread Lakshmi Sailaja
Hello,

I am supposed to write a program that will telnet to a remote server and
execute some commands. I get the following error:
"timed-out waiting for command prompt at  line "

This is because the prompt is not set correctly. Can you please tell me what
the prompt value should be set to?

how can I determine my remote machines prompt?

Thanks in advance!!

Regards,
Sailaja


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




RE: Net::Telnet - Variable in Prompt

2007-06-12 Thread Lakshmi Sailaja
I am if my question was brief.

$prompt is a scalar variable.

like this:
$sub = "xyz";
$prompt = "L:\\$sub";

my $t = Net::Telnet->new(
Timeout => 10,
Prompt  => "/$prompt/"
);

Thanks & Regards,
Lakshmi
952-833-1220

-Original Message-
From: Chas Owens [mailto:[EMAIL PROTECTED]
Sent: Tuesday, June 12, 2007 3:29 PM
To: [EMAIL PROTECTED]
Cc: Martin Barth; beginners@perl.org
Subject: Re: Net::Telnet - Variable in Prompt


On 6/12/07, Lakshmi Sailaja <[EMAIL PROTECTED]> wrote:
> But it did not work. I was getting the below error:
> "timed-out waiting for command prompt at  line "
snip

This code works for me.

#!/usr/bin/perl

use strict;
use warnings;

use Net::Telnet;

#my propmt is /home/user>
my $prompt = '>$';

my $t = Net::Telnet->new(
Timeout => 10,
Prompt  => "/$prompt/"
);

$t->open("widomaker.com");
$t->login("user", "pass");
my @lines = $t->cmd("who");
print @lines;



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Net::Telnet - Variable in Prompt

2007-06-12 Thread Chas Owens

On 6/12/07, Lakshmi Sailaja <[EMAIL PROTECTED]> wrote:

But it did not work. I was getting the below error:
"timed-out waiting for command prompt at  line "

snip

This code works for me.

#!/usr/bin/perl

use strict;
use warnings;

use Net::Telnet;

#my propmt is /home/user>
my $prompt = '>$';

my $t = Net::Telnet->new(
   Timeout => 10,
   Prompt  => "/$prompt/"
);

$t->open("widomaker.com");
$t->login("user", "pass");
my @lines = $t->cmd("who");
print @lines;

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




RE: Net::Telnet - Variable in Prompt

2007-06-12 Thread Lakshmi Sailaja
But it did not work. I was getting the below error:
"timed-out waiting for command prompt at  line "

Thanks & Regards,
Lakshmi
952-833-1220

-Original Message-
From: Martin Barth [mailto:[EMAIL PROTECTED]
Sent: Tuesday, June 12, 2007 2:23 PM
To: beginners@perl.org
Cc: [EMAIL PROTECTED]
Subject: Re: Net::Telnet - Variable in Prompt


On Tue, 12 Jun 2007 11:56:12 -0500
"Lakshmi Sailaja" <[EMAIL PROTECTED]> wrote:

> Hi,
>
> Is there a way to use a variable in the Prompt parameter like the below
> line?
>
>  my $telnet = Net::Telnet->new([HOST => "$server",]
> [PROMPT => /$prompt/,]);
>
> Thanks & Regards,
> Lakshmi
> 952-833-1220
>
>

hi,

this should work. but the promt is only set once. so if the var changes, the
prompt will remain.

HTH

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Net::Telnet - Variable in Prompt

2007-06-12 Thread Martin Barth
On Tue, 12 Jun 2007 11:56:12 -0500
"Lakshmi Sailaja" <[EMAIL PROTECTED]> wrote:

> Hi,
> 
> Is there a way to use a variable in the Prompt parameter like the below
> line?
> 
>  my $telnet = Net::Telnet->new([HOST => "$server",]
> [PROMPT => /$prompt/,]);
> 
> Thanks & Regards,
> Lakshmi
> 952-833-1220
> 
> 

hi,

this should work. but the promt is only set once. so if the var changes, the 
prompt will remain.

HTH

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Net::Telnet - Variable in Prompt

2007-06-12 Thread Lakshmi Sailaja
Hi,

Is there a way to use a variable in the Prompt parameter like the below
line?

 my $telnet = Net::Telnet->new([HOST => "$server",]
[PROMPT => /$prompt/,]);

Thanks & Regards,
Lakshmi
952-833-1220


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Net::Telnet --help required

2007-05-17 Thread a b

Hi Jay,

Thanks for your resoponse. I tried with the suggested but it failed due to
timed out
(j.pl)
use Net::Telnet;
my $t = new Net::Telnet;
$t->open("slias10");
print($t->waitfor('/login:.*$/'));
$t->print("root");
sleep(2);
@forecast=$t->cmd("/usr/bin/ls");
print @forecast;


C:\>perl j.pl

HP-UX slias10 B.11.31 U ia64 (ta)

command timed-out at j.pl line 7
login:


Please, suggest i am able to see the

On 5/16/07, Jay Savage <[EMAIL PROTECTED]> wrote:


On 5/16/07, a b <[EMAIL PROTECTED]> wrote:
> Hello,
> I am trying to telnet to all m/c for which i haven't set password(only
root
> is a valid user)
> any body can telnet using root user
> But when i try to access through perl it
> 
> use warnings;
> use Net::Telnet;
>
> my $t = new Net::Telnet (Timeout => 10,Prompt => '/bash\$ $/');
> my @line;
> $t->open("host1");
> $t->waitfor('/login:.*$/');
> $t->print("root");
> $forecast=$t->print("/usr/bin/ls");
> print $forecast;
>
>
> O/P : 1
>
> OR
>
> use warnings;
> use Net::Ping;
> use Net::Telnet;
>
> my $t = new Net::Telnet (Timeout => 10,Prompt => '/bash\$ $/');
> my @line;
> $t->open("host1");
> $t->login("root","");
> $result=$t->cmd("/usr/bin/ls");
> print $result;
>
> O/P : timed-out waiting for password prompt at j.pl line 8
>
>

Close.

You do the login correctly in example 1, but then you use print to
issue the command. all that does is print the string "/usr/bin/ls\n"
to the remote terminal and return 1 to let you know the command
succeeded. If you want the output of the remote command, you need to
use cmd (in list context)

In example 2, you don't pass a password to login or waitfor one, so
you never login. You do, though, use cmd, which is what you want,
although you need list context:

$t->open("host1");
$t->waitfor('/login:.*$/');
$t->print("root");
my @forecast=$t->cmd("/usr/bin/ls");
my $scalar_forecast = join "", @forecast;
# or join'\n', I don't remember if cmd returns newlines or not

HTH,

-- jay
--
This email and attachment(s): [  ] blogable; [ x ] ask first; [  ]
private and confidential

daggerquill [at] gmail [dot] com
http://www.tuaw.com  http://www.downloadsquad.com  http://www.engatiki.org

values of β will give rise to dom!



Re: Net::Telnet --help required

2007-05-16 Thread Jay Savage

On 5/16/07, a b <[EMAIL PROTECTED]> wrote:

Hello,
I am trying to telnet to all m/c for which i haven't set password(only root
is a valid user)
any body can telnet using root user
But when i try to access through perl it

use warnings;
use Net::Telnet;

my $t = new Net::Telnet (Timeout => 10,Prompt => '/bash\$ $/');
my @line;
$t->open("host1");
$t->waitfor('/login:.*$/');
$t->print("root");
$forecast=$t->print("/usr/bin/ls");
print $forecast;


O/P : 1

OR

use warnings;
use Net::Ping;
use Net::Telnet;

my $t = new Net::Telnet (Timeout => 10,Prompt => '/bash\$ $/');
my @line;
$t->open("host1");
$t->login("root","");
$result=$t->cmd("/usr/bin/ls");
print $result;

O/P : timed-out waiting for password prompt at j.pl line 8




Close.

You do the login correctly in example 1, but then you use print to
issue the command. all that does is print the string "/usr/bin/ls\n"
to the remote terminal and return 1 to let you know the command
succeeded. If you want the output of the remote command, you need to
use cmd (in list context)

In example 2, you don't pass a password to login or waitfor one, so
you never login. You do, though, use cmd, which is what you want,
although you need list context:

$t->open("host1");
$t->waitfor('/login:.*$/');
$t->print("root");
my @forecast=$t->cmd("/usr/bin/ls");
my $scalar_forecast = join "", @forecast;
# or join'\n', I don't remember if cmd returns newlines or not

HTH,

-- jay
--
This email and attachment(s): [  ] blogable; [ x ] ask first; [  ]
private and confidential

daggerquill [at] gmail [dot] com
http://www.tuaw.com  http://www.downloadsquad.com  http://www.engatiki.org

values of β will give rise to dom!


Net::Telnet --help required

2007-05-16 Thread a b

Hello,
I am trying to telnet to all m/c for which i haven't set password(only root
is a valid user)
any body can telnet using root user
But when i try to access through perl it

use warnings;
use Net::Telnet;

my $t = new Net::Telnet (Timeout => 10,Prompt => '/bash\$ $/');
my @line;
$t->open("host1");
$t->waitfor('/login:.*$/');
$t->print("root");
$forecast=$t->print("/usr/bin/ls");
print $forecast;


O/P : 1

OR

use warnings;
use Net::Ping;
use Net::Telnet;

my $t = new Net::Telnet (Timeout => 10,Prompt => '/bash\$ $/');
my @line;
$t->open("host1");
$t->login("root","");
$result=$t->cmd("/usr/bin/ls");
print $result;

O/P : timed-out waiting for password prompt at j.pl line 8


Please, help me to understand the solution of it.
I need this as urgent requirement for house-keeping activities

Thanks in adavance

_abhi


Net::Telnet errmode

2006-05-07 Thread jm

i use Net::Telnet to connect to a server and run tests for several
hours.  the script will normally die in various places in the script,
apparently due to losing connection to the server.

i found in the documentation about changing Net::Telnet's Errmode to
'return' so it will return to the script; what i haven't found yet is
where i can read Errmode's value so the script will know to
re-establish connectivity and continue testing.

the error message is "write error: filehandle isn't open" which
appears to be a Net::Telnet-specific message.  i don't have the output
in front of me but if i remember correctly, it happens when i print
($t->print("...")) to the telnet connection.

any help on how to read Net::Telnet's Errmode status to know the
connection has died would be greatly appreciated.

thanks,
joe

--
since this is a gmail account, please verify the mailing list is
included in the reply to addresses

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




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]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




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]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Re: Help required about NET::TELNET

2005-12-05 Thread Stephen Kratzer
Mazhar,

try:
$telnet->waitfor(Match => '/login: $/i');
and
$telnet->waitfor(Match => '/password: $/i');

Vishal,

Right, you want to wait for the device to return something that will match the 
expression between the slashes. In that example, you'd be waiting for the 
device to return a login prompt ending with a space and you'd ignore 
capitalization.

On Monday 05 December 2005 10:19, [EMAIL PROTECTED] wrote:
> Hey Mazhar,
>
> I don't know much about perl, but in the $telnet->waitfor method, what does
> the weird parameter mean ('/login: $/i')? I thought that $ means a scalar
> variable in perl. What do the forward slashes do here? Some sort of regular
> expression??
>
> Vishal
>
> Quoting Mazhar <[EMAIL PROTECTED]>:
> > Hi Folks,
> > I have installed the module NET::TELNET from CPAN and when i try to
> > execute the below simple pgm,
> >
> > ---
> > use Net::Telnet;
> > $telnet = new Net::Telnet ( Timeout=>100,Errmode=>'die');
> > $telnet->open('202.177.129.37');
> >  $telnet->waitfor('/login: $/i');
> >  $telnet->print('root');
> >  $telnet->waitfor('/password: $/i');
> >  $telnet->print('[EMAIL PROTECTED]');
> >  print $telnet->cmd('who');
> >
> > -
> >- The Output of the above program is
> > pattern match read eof at prog.pl line 12
> >
> >
> > Please help me out folks as where may be the problem
> >
> > Regards
> > Mazhar
>
> 
> This mail sent through www.mywaterloo.ca

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Re: Help required about NET::TELNET

2005-12-05 Thread vmalik
Hey Mazhar,

I don't know much about perl, but in the $telnet->waitfor method, what does the
weird parameter mean ('/login: $/i')? I thought that $ means a scalar variable
in perl. What do the forward slashes do here? Some sort of regular expression??

Vishal


Quoting Mazhar <[EMAIL PROTECTED]>:

> Hi Folks,
>     I have installed the module NET::TELNET from CPAN and when i try to
> execute the below simple pgm,
> 
> ********-------
> use Net::Telnet;
> $telnet = new Net::Telnet ( Timeout=>100,Errmode=>'die');
> $telnet->open('202.177.129.37');
>  $telnet->waitfor('/login: $/i');
>  $telnet->print('root');
>  $telnet->waitfor('/password: $/i');
>  $telnet->print('[EMAIL PROTECTED]');
>  print $telnet->cmd('who');
> 
> --
> The Output of the above program is
> pattern match read eof at prog.pl line 12
> 
> 
> Please help me out folks as where may be the problem
> 
> Regards
> Mazhar
> 





This mail sent through www.mywaterloo.ca

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Help required about NET::TELNET

2005-12-05 Thread Mazhar
Hi Folks,
I have installed the module NET::TELNET from CPAN and when i try to
execute the below simple pgm,

---
use Net::Telnet;
$telnet = new Net::Telnet ( Timeout=>100,Errmode=>'die');
$telnet->open('202.177.129.37');
 $telnet->waitfor('/login: $/i');
 $telnet->print('root');
 $telnet->waitfor('/password: $/i');
 $telnet->print('[EMAIL PROTECTED]');
 print $telnet->cmd('who');

--
The Output of the above program is
pattern match read eof at prog.pl line 12


Please help me out folks as where may be the problem

Regards
Mazhar


Net::Telnet Updating Prompt?

2005-10-11 Thread Angerstein
Hello,
I have a small issue with net::telnet 3.03.

The Device I want to connect aus an OS-Level CLI and a
Application-Level CLI.

I have to log in to OS-Level to gai Access to Application level.

Now, the problem is, the command prompt of the application is different from
the prompt of the Os (hanging the OS-Level Prompt is not Possible, because
its embedded).

So Net::Telnet logs in and save the prompt. So it don´t need to rematch the
prompt with the given expression.

Is it possible to update the internal Object-attribute ($last_prompt)?

Is there an easy way?

Any idea at all?


thanks a lot for any comment.

Bastian



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




why is the $output returned by NET::Telnet->cmd is empty [ ], dump_log is Ok

2005-06-27 Thread MEENA SELVAM

according to dump_log when remote cmd is executed,
the remote side sends the output, but printing output
shows only []. where can i suspect?
meena
--- MEENA SELVAM <[EMAIL PROTECTED]> wrote:

> 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]
> 
> 
> 
> 
> 




 
Yahoo! Sports 
Rekindle the Rivalries. Sign up for Fantasy Football 
http://football.fantasysports.yahoo.com

-- 
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: where to get perldoc Net::Telnet? missing in the perldoc from perldoc.perl.org

2005-06-20 Thread Wijaya Edward
Which version are you using? 
Check the standard CPAN site, you will find:
http://search.cpan.org/~jrogers/Net-Telnet-3.03/lib/Net/Telnet.pm

HtH
--
Regards,
Edward WIJAYA
SINGAPORE

- Original Message -
From: MEENA SELVAM <[EMAIL PROTECTED]>
Date: Tuesday, June 21, 2005 12:29 pm
Subject: where to get perldoc Net::Telnet? missing in the perldoc from 
perldoc.perl.org

> Hi,
> I do not have the  Net::Telnet in the perldoc i
> downloaded from perldoc.perl.org. even
> http://perldoccom/cspan/Net/Telnet.Html page is not
> working
> 
> meena
> 
> __
> 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]
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
> 
> 
> 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




where to get perldoc Net::Telnet? missing in the perldoc from perldoc.perl.org

2005-06-20 Thread MEENA SELVAM
Hi,
I do not have the  Net::Telnet in the perldoc i
downloaded from perldoc.perl.org. even
http://perldoccom/cspan/Net/Telnet.Html page is not
working

meena

__
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]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Re: redefining Net::Telnet "escape" character

2005-02-28 Thread Joe Mecklin
On Mon, 28 Feb 2005 10:05:32 -0500, Wiggins d'Anconia
<[EMAIL PROTECTED]> wrote:
> Joe Mecklin wrote:
> > ok, per the instructions, binmode only converts CR LF to \n, which is
> > not what i'm looking for.
> >
> 
> Out of curiousity isn't the escape character used for client side
> handling?  In this case why would you need to worry about the escape
> character, as you can drop to a subshell from within Perl, and since
> this is talking directly to a telnet session it doesn't really make
> since to drop to a subshell, as that subshell would be your Perl script???
> 

my apologies, apparently i'm leaving out too many details to be
clearly understood...

net::telnet is building a telnet session (with an escape character of
^])  to a solaris server.

the solaris server requires a login with SECURID, requiring a manual
(unprogrammable) login for every connection.

once connected, i am immediately entered into a menu script which
allows selection of multiple auxiliary systems; each of these systems
is a piece of Cisco hardware which also has auxiliary systems
connected to them.

each Cisco system has a restricted shell with a minimal telnet
command.  this telnet command only allows ip and port for arguments;
it does not allow the user to change its internal escape character,
which is also the default ^].

once i connect to each of these systems for testing and want to drop
connection, using the default ^] drops me all the way back to my local
prompt, requiring another manual connection to the frontend solaris
server.  not being able to maintain connection within the solaris
server negates the usefulness of the script completely.

the fact that ^] is the recognized escape character for every
connection i make in the sequence is why i need to redefine it in my
initial connection, since i am unable to redefine it in my subsequent
connections

.
.
.

> > sub login_system
> > {
> >   my ($prematch, $match) = $t->waitfor(String => "login:", Errmode => 
> > 'return');
> >   print "$prematch $match\n\n";
> >   print "\nchanging \"escape\" character";
> >   print "\n";
> >   $t->put("^]");
> 
> My first guess is that the above is sending '^' and then ']' instead of
> the control charactert that you want. So you should convert the above to
> the hex representation of the character so Perl knows what you are
> really talking about, or use the Ctrl+V Ctrl+] sequence.
> 

i do use Ctrl+V Ctrl+] in my code to enter the control sequence, but
that actual sequence doesn't display properly in the email so i
converted it to an ascii sequence for reading purposes.

this is a modified version of a script that works fine; the
differences are in the destination systems, which are radically
different in responses and connection sequences.  on the working
script i can modify ^] in the downstream telnet connections; as noted
above, on these systems that is not an option.

.
.
.


> > so escaping back to the normal telnet prompt to change the escape
> > character doesn't work.  a normal telnet "escape" character is ^] ...
> > i need to know how to change that from ^] to ^[ (or ^A or whatever)
> > within net::telnet
> >
> > again, tia for any help
> > joe
> >
> 
> Did you turn on the debugging switch?
> 
> http://danconia.org
> 

i did not use debugging; the script works as far as it goes.  i need
the proper external command or net::telnet function/sub call to modify
the default definition of the escape character so that the desired
character (^[ rather than ^]) is passed, and debug will not give me
that information.

thanks for the suggestions, though.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Re: redefining Net::Telnet "escape" character

2005-02-28 Thread Wiggins d'Anconia
Joe Mecklin wrote:
ok, per the instructions, binmode only converts CR LF to \n, which is
not what i'm looking for.
Out of curiousity isn't the escape character used for client side 
handling?  In this case why would you need to worry about the escape 
character, as you can drop to a subshell from within Perl, and since 
this is talking directly to a telnet session it doesn't really make 
since to drop to a subshell, as that subshell would be your Perl script???

here is a condensed version of the script:
###
#!/usr/bin/perl
use ASI::WebDB;
use Term::ReadKey;
use Net::Telnet ();
my $login = "";
my $securid = "";
print "UID: ";
chomp($login = <>);
ReadMode noecho;
print "SECURID: ";
chomp($securid = <>);
ReadMode restore;
$t = new Net::Telnet (Timeout => 10);
$t->open("x.x.x.x");
print "\nlogging in to system";
&login_system;
sub login_system
{
my ($prematch, $match) = $t->waitfor(String => "login:", Errmode => 
'return');
print "$prematch $match\n\n";
print "\nchanging \"escape\" character";
print "\n";
$t->put("^]");
My first guess is that the above is sending '^' and then ']' instead of 
the control charactert that you want. So you should convert the above to 
the hex representation of the character so Perl knows what you are 
really talking about, or use the Ctrl+V Ctrl+] sequence.

($prematch, $match) = $t->waitfor(String => "telnet", Errmode => 
'return');
print "$prematch $match\n\n";
print "\nback in telnet";
print "\n";
$t->print("set escape ^[");
$t->waitfor(String => "escape character is '^['.");
$t->print ("");
$t->waitfor(String => "login:", Errmode => 'return');
print "\nEntering stoak account login";
$t->print("$login");
$t->waitfor(String => "PASSCODE:", Errmode => 'return');
print "\nEntering SECURID PASSCODE";
$t->print("$securid");
}
##
i get "pattern match timed-out at ./script-name line 102" which is
$t->waitfor(String => "escape character is '^['.");
so escaping back to the normal telnet prompt to change the escape
character doesn't work.  a normal telnet "escape" character is ^] ...
i need to know how to change that from ^] to ^[ (or ^A or whatever)
within net::telnet
again, tia for any help
joe
Did you turn on the debugging switch?
http://danconia.org
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: redefining Net::Telnet "escape" character

2005-02-28 Thread Joe Mecklin
ok, per the instructions, binmode only converts CR LF to \n, which is
not what i'm looking for.

here is a condensed version of the script:

###

#!/usr/bin/perl

use ASI::WebDB;
use Term::ReadKey;
use Net::Telnet ();

my $login = "";
my $securid = "";

print "UID: ";
chomp($login = <>);
ReadMode noecho;
print "SECURID: ";
chomp($securid = <>);
ReadMode restore;

$t = new Net::Telnet (Timeout => 10);

$t->open("x.x.x.x");

print "\nlogging in to system";
&login_system;


sub login_system
{
my ($prematch, $match) = $t->waitfor(String => "login:", Errmode => 
'return');
print "$prematch $match\n\n";
print "\nchanging \"escape\" character";
print "\n";
$t->put("^]");
($prematch, $match) = $t->waitfor(String => "telnet", Errmode => 
'return');
print "$prematch $match\n\n";
print "\nback in telnet";
print "\n";
$t->print("set escape ^[");
$t->waitfor(String => "escape character is '^['.");
$t->print ("");
$t->waitfor(String => "login:", Errmode => 'return');
print "\nEntering stoak account login";
$t->print("$login");

$t->waitfor(String => "PASSCODE:", Errmode => 'return');
print "\nEntering SECURID PASSCODE";
$t->print("$securid");
}

##

i get "pattern match timed-out at ./script-name line 102" which is

$t->waitfor(String => "escape character is '^['.");

so escaping back to the normal telnet prompt to change the escape
character doesn't work.  a normal telnet "escape" character is ^] ...
i need to know how to change that from ^] to ^[ (or ^A or whatever)
within net::telnet

again, tia for any help
joe

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Re: redefining Net::Telnet "escape" character

2005-02-25 Thread Joe Mecklin
i'll try it when i get back to work, though i don't see how binmode
will tell me what net::telnet command i need to use to redefine a
character sequence, or what external command i'll need to call to
accomplish that.  thanks for the suggestion, though.



On Fri, 25 Feb 2005 12:13:41 -0500, [EMAIL PROTECTED]
<[EMAIL PROTECTED]> wrote:
> Joe,
> Try turning binmod on. If it fails post some code and a bit more od a 
> description of what you are trying to do.
> hth,
> Mark G.
> 
> - Original Message -
> From: Joe Mecklin <[EMAIL PROTECTED]>
> Date: Friday, February 25, 2005 8:44 am
> Subject: redefining Net::Telnet "escape" character
> 
> > i sent this to the comp.lang.perl.modules newsgroup as the
> > documentation suggests and got no response at all, so i thought i'd
> > see if anyone here may be able to help.
> >
> > i'm using net::telnet to connect to a remote script (rather than a
> > login).  the script internally uses "^]" to step back through itself,
> > conflicting with the default escape telnet character.  this wouldn't
> > be a problem per se except that the login to the system uses securid
> > (requiring manual login each time), and once i connect i need to step
> > through verifying several hundred auxiliary systems; being forced to
> > manually login for each new test would negate the benefits of a
> > script.
> >
> > i had the idea of, once connecting, dropping back to telnet and doing
> > a "set escape ^[" but then realized net::telnet may not drop back
> > to a
> > telnet prompt as the telnet command would (no i haven't verified this
> > for sure yet because i had my "epiphany" just as i was leaving work
> > for the day, and i've been forced to take the rest of the week off for
> > personal reasons).
> >
> > question: what is one/the way to redefine the net::telnet escape
> > character from ^] to another ^[ (or anything else?)
> >
> > tia,
> > joe
> >
> > --
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> > <http://learn.perl.org/> <http://learn.perl.org/first-response>
> >
> >
> >
> 
>

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Re: redefining Net::Telnet "escape" character

2005-02-25 Thread mgoland
Joe,
Try turning binmod on. If it fails post some code and a bit more od a 
description of what you are trying to do.
hth,
Mark G.

- Original Message -
From: Joe Mecklin <[EMAIL PROTECTED]>
Date: Friday, February 25, 2005 8:44 am
Subject: redefining Net::Telnet "escape" character

> i sent this to the comp.lang.perl.modules newsgroup as the
> documentation suggests and got no response at all, so i thought i'd
> see if anyone here may be able to help.
> 
> i'm using net::telnet to connect to a remote script (rather than a
> login).  the script internally uses "^]" to step back through itself,
> conflicting with the default escape telnet character.  this wouldn't
> be a problem per se except that the login to the system uses securid
> (requiring manual login each time), and once i connect i need to step
> through verifying several hundred auxiliary systems; being forced to
> manually login for each new test would negate the benefits of a
> script.
> 
> i had the idea of, once connecting, dropping back to telnet and doing
> a "set escape ^[" but then realized net::telnet may not drop back 
> to a
> telnet prompt as the telnet command would (no i haven't verified this
> for sure yet because i had my "epiphany" just as i was leaving work
> for the day, and i've been forced to take the rest of the week off for
> personal reasons).
> 
> question: what is one/the way to redefine the net::telnet escape
> character from ^] to another ^[ (or anything else?)
> 
> tia,
> joe
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
> 
> 
> 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




redefining Net::Telnet "escape" character

2005-02-25 Thread Joe Mecklin
i sent this to the comp.lang.perl.modules newsgroup as the
documentation suggests and got no response at all, so i thought i'd
see if anyone here may be able to help.

i'm using net::telnet to connect to a remote script (rather than a
login).  the script internally uses "^]" to step back through itself,
conflicting with the default escape telnet character.  this wouldn't
be a problem per se except that the login to the system uses securid
(requiring manual login each time), and once i connect i need to step
through verifying several hundred auxiliary systems; being forced to
manually login for each new test would negate the benefits of a
script.

i had the idea of, once connecting, dropping back to telnet and doing
a "set escape ^[" but then realized net::telnet may not drop back to a
telnet prompt as the telnet command would (no i haven't verified this
for sure yet because i had my "epiphany" just as i was leaving work
for the day, and i've been forced to take the rest of the week off for
personal reasons).

question: what is one/the way to redefine the net::telnet escape
character from ^] to another ^[ (or anything else?)

tia,
joe

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Re: Could anyone please answer a $telnetAte = Net::Telnet -> new...

2004-07-20 Thread Jenda Krynicky
From: Marco Perl <[EMAIL PROTECTED]>
> I use CYGWIN on win-2000 with a ô$ö prompt and run
>
> my .pl to telnet to a VxWorks station. doing it manually this is what
> I follow:
>
> telnet 
>
> open 144.248.176.132 
>
> then I get the login prompt which is ôVxWorks Login: ô
>
> and I enter ômarcoö
>
> and the ôpassword: ô which I enter ôsystemö
>
> then I get the vxworks prompt ô-> ô
>
> here I do a ôpwdö and get the result and then the prompt again.
>
> Below is my code but does not log me in.
>
> $ip  = '144.248.176.132' ;
>
> print( "\n- Opening Telnet session to $ip\n" ) ;
>
>$telnetAte = Net::Telnet -> new( Timeout => 60 ) ;
>
>$telnetAte -> open( $ip ) ;
>
>$telnetAte -> waitfor( '/VxWorks login:/' ) ;

A few lines above you said the loing prompt is "VxWorks Login:", with
capital L. This could be a problem.

Jenda
= [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Net::Telnet set terminal

2004-06-28 Thread Ramprasad A Padmanabhan
I have a problem with Net::Telnet ( again ) 
When I connect to a united linux machine the server does not recognize
terminaltype 'network' and the connection just hangs.


Can I use telnet with a terminal type "vt100" in Net::Telnet

Thanks
Ram



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Re: Net::Telnet login problem

2004-06-11 Thread Wiggins d Anconia
> Hi,
>   I have written a web based utility that requires to login to several
> machines and do some routine tasks
> MY script uses Net::Telnet and works fine on most machines
> I use the the login() method to login to the servers
> 
> The problem comes when the server sometimes has a different prompt
> password like
> 
> login: ram
> Password for ram:
> 
> Instead of just "password:" . I can get over this by using waitfor() and
> print() but the solution is patchy, because I have to write a seperate
> procedure for some hosts.
> 
> Can I change login() or write my own generic login()  that would work on
> all hosts
> 

Ah, the beauty of Perl and OOP in general.  You should be able to
subclass Net::Telnet, then just supply your own 'login' method. This
should be relatively trivial.  Create a module, 

Net::Telnet::Ram

Or something similar, and have it inherit from Net::Telnet

package Net::Telnet::Ram;
use Net::Telnet;
our @ISA qw(Net::Telnet);

And provide your own login method,

sub login { ... }

Then when you instantiate your object in your script just switch the
call to use the subclass,

use Net::Telnet::Ram;
my $connect = new Net::Telnet::Ram ( ... );

Pretty much everything else is the same. 

The tricky part is going to be what to do with 'login' above. Probably
you will need to copy and paste most of the code from the original
login, and make your adjustments where you need them.  You have the
option of calling SUPER::login within your module's 'login' but in this
case I don't think it will be appropriate.  Obviously in the future you
will need to pay particular attention to changes in that method if/when
you upgrade Net::Telnet to make sure any bugs fixed in 'login' are also
fixed in your version, as presumably they will have been copied. 

Alternatively you could just hack your version of the module, but to me
this is more of a maintenance nightmare than subclassing it.

Check out perldoc for specifics related to module creation, oop, etc.
the above lines of code may not be complete.

HTH,

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Re: Net::Telnet login problem

2004-06-10 Thread Ziggy
On Friday 11 June 2004 07:50, Ramprasad A Padmanabhan wrote:
> Hi,
>   I have written a web based utility that requires to login to several
> machines and do some routine tasks
> MY script uses Net::Telnet and works fine on most machines
> I use the the login() method to login to the servers
>
> The problem comes when the server sometimes has a different prompt
> password like
>
> login: ram
> Password for ram:
>
> Instead of just "password:" . I can get over this by using waitfor() and
> print() but the solution is patchy, because I have to write a seperate
> procedure for some hosts.
>
> Can I change login() or write my own generic login()  that would work on
> all hosts
>
> Thanks
> Ram

Yes. You can write your own function to do the login. 

RamsLogin {
waitfor(@_[0])
print(@_[1])

waitfor(@_[2]
print(@_[1])
}

More or less like what I wrote, you'll figure it out. Since I don't know how 
the Net::Telnet package works that's the best I can do.
-- 
Linux
2.6.6
(Gentoo)
i686 P4


If wishes were horses, then beggars would be thieves.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Net::Telnet login problem

2004-06-10 Thread Ramprasad A Padmanabhan
Hi,
  I have written a web based utility that requires to login to several
machines and do some routine tasks
MY script uses Net::Telnet and works fine on most machines
I use the the login() method to login to the servers

The problem comes when the server sometimes has a different prompt
password like

login: ram
Password for ram:

Instead of just "password:" . I can get over this by using waitfor() and
print() but the solution is patchy, because I have to write a seperate
procedure for some hosts.

Can I change login() or write my own generic login()  that would work on
all hosts

Thanks
Ram





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Re: Net::Telnet executing commands on remote shell after executing su

2004-05-12 Thread Wiggins d Anconia
> Hi, 
> 
>   I am using Net::Telnet and getting a new shell on a remote machine
> all my commands work fine
> Now suppose I become root using "su" and "pass" I am not able to
> execute commands on this root shell
> Can anyone show me How  I can do this
> 

I believe you are going to need to use the read/wait_for idiom inside of
a loop simulating the command/output environment for the su subshell.

>From the Net::Telnet docs,

"Consider using a combination of print() and waitfor() as an alternative
to this method when it doesn't do what you want, e.g. the command you
send prompts for input."

Essentially once you have su'd you are going to be sent the su prompt,
wait for that, then do 'print' to send a command, then wait for the
prompt again, etc.

I *believe* (aka I haven't done it before) that this will work. Check
the Net::Telnet docs for much more information on this.  You might also
consider skipping the 'su' stuff altogether and see if sudo can be used
as an alternative.  Then you can have access to specific commands,
without a password if desired.

HTH,

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Net::Telnet executing commands on remote shell after executing su

2004-05-11 Thread Ramprasad A Padmanabhan
Hi, 

  I am using Net::Telnet and getting a new shell on a remote machine
all my commands work fine
Now suppose I become root using "su" and "pass" I am not able to
execute commands on this root shell
Can anyone show me How  I can do this

THanks
Ram



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Always Timing Out in Net::Telnet :(

2004-02-10 Thread Thind, Aman
Hello Friends,

I have to run a command on my unix box through a script running on my
windows m/c.

Here's my code which is nothing but the example in perldoc of the module :

use Net::Telnet ();
$username = "myusername";
$passwd = "mypasswd";

$t = new Net::Telnet (Timeout => 10, Prompt => '/login \(dell001rs\): $/');

$t->open('my_machine_ip');

$t->login($username, $passwd);
@lines = $t->cmd("who");
print @lines;

Now, as per the module documentation , specifying the Prompt is very
essential if it is not like the default '/[\$%#>] $/ '
It searches through the input stream for the prompt and performs actions
accordingly.
If it is not able to find the prompt in the stream, it shall time-out
looking for the login prompt.

When I login to my machine , the login prompt is like :

login (dell001rs): 

And after logging in the prompt becomes :

[EMAIL PROTECTED] $

What should I add after "Prompt => " while creating a new session ?

No matter what I try it always aborts with the msg : "timed-out waiting for
login prompt at J:\net.pl line 10" :((

Thanx a lot
Aman









-Original Message-
From: Thind, Aman [mailto:[EMAIL PROTECTED] 
Sent: 05 February 2004 10:55
To: [EMAIL PROTECTED]
Subject: Remote script execution


Hello Friends,

I would be really grateful if someone could help me out with this.

I want to write a script that when executed will get lots of details from 10
different Unix(AIX) and Windows(XP) boxes and generate a report.

The details to be gathered about the machines include :

1) Names and versions of all the softwares on the machines.

2) Disk space usage.

Etc...

Please guide me how I could go about it...

I am not aware of how a script running on 1 machine take data from commands
that are to be run on other...(like rsh)

Thanks in advance
-aman


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Re: usage of Net::Telnet

2004-01-21 Thread lobach
This is what I do..  The only difference I see is that you haven't logged
on..
   my $rmhost = new Net::Telnet (Host => $nodesrch,  Timeout => 100 );
 $rmhost->login($uname_EGATE, $passwd_EGATE);
   $cat_command='cat ./data/journal/chopler';
  @cat_result=$rmhost->cmd($cat_command);
   print  @cat_result;

"Tim" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Try using input_log and output_log when you instantiate your telnet class.
>
>  $obj = new Net::Telnet ([Binmode=> $mode,]
>
>  [Cmd_remove_mode => $mode,]
>
>  [Dump_Log   => $filename,]
>
>  [Errmode=> $errmode,]
>
>  [Fhopen => $filehandle,]
>
>  [Host   => $host,]
>
>  [Input_log  => $file,]
>
>  [Input_record_separator => $chars,]
>
>  [Option_log => $file,]
>
>  [Ors=> $chars,]
>
>  [Output_log => $file,]
>
>  [Output_record_separator => $chars,]
>
>  [Port   => $port,]
>
>  [Prompt => $matchop,]
>
>  [Rs => $chars,]
>
>  [Telnetmode => $mode,]
>
>  [Timeout=> $secs,]);
>
> This info can be further illustrated by entering 'perldoc
> Net::Telnet'  form the command line.
>
>
> At 10:46 AM 1/20/04 +, you wrote:
>
> >Hi ,
> >
> >I am trying to use the Net::Telnet module after installing in my solaris
2.8
> >machine.
> >But I am unable to get the output.
> >
> >There is no error messages either.The program just exists.
> >Could you help me out on this please...
> >
> >#!/usr/bin/perl -w
> >use Net::Telnet ();
> >
> >$t = new Net::Telnet (Timeout => 1000,
> >   Port   => 8667);
> >$t->open("ss-ps.demon.net");
> >
> >@output = $t->cmd("01244530112");
> >print @output;
> >
>
>---
-
> >
> >
> >regards,
> >
> >Ajitpal Singh,
> >Wipro Technologies.
> >Finchley,London.
> >Tel:044 208 495 6317
> >Mobile:07900534143
> >
> >



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Re: usage of Net::Telnet

2004-01-20 Thread Tim
Try using input_log and output_log when you instantiate your telnet class.

$obj = new Net::Telnet ([Binmode=> $mode,]

[Cmd_remove_mode => $mode,]

[Dump_Log   => $filename,]

[Errmode=> $errmode,]

[Fhopen => $filehandle,]

[Host   => $host,]

[Input_log  => $file,]

[Input_record_separator => $chars,]

[Option_log => $file,]

[Ors=> $chars,]

[Output_log => $file,]

[Output_record_separator => $chars,]

[Port   => $port,]

[Prompt => $matchop,]

[Rs => $chars,]

[Telnetmode => $mode,]

[Timeout=> $secs,]);

This info can be further illustrated by entering 'perldoc 
Net::Telnet'  form the command line.

At 10:46 AM 1/20/04 +, you wrote:

Hi ,

I am trying to use the Net::Telnet module after installing in my solaris 2.8
machine.
But I am unable to get the output.
There is no error messages either.The program just exists.
Could you help me out on this please...
#!/usr/bin/perl -w
use Net::Telnet ();
$t = new Net::Telnet (Timeout => 1000,
  Port   => 8667);
$t->open("ss-ps.demon.net");
@output = $t->cmd("01244530112");
print @output;


regards,

Ajitpal Singh,
Wipro Technologies.
Finchley,London.
Tel:044 208 495 6317
Mobile:07900534143


-Original Message-
From: Jenda Krynicky [mailto:[EMAIL PROTECTED]
Sent: 20 January 2004 10:43
To: [EMAIL PROTECTED]
Subject: Re: Saying an item is empty
From: "Trina Espinoza" <[EMAIL PROTECTED]>
> I would like to know how  I would say if $item equals $tempitem OR if
> $item is empty(the variable is  a placeholder that has nothing in it),
> execute command.
I'd revert the tests. First see whether it's empty, then whether it
equals something:
if (!defined $item or $item eq $tempitem) {
do something
> Are either of these saying the above statement
> because I don't seem to be getting the expected results.
>
> If ($item =~ /^(\D+)(\d+)/ {)
> If ($1 eq !$tempitem) {
I guess the capital "I"s were introduced by your mail client (I know
some programs think they know better:-}
Anyway the
$1 eq !$tempitem
doesn't really make sense.
If you want to say "$1 does not equal to $tempitem" it should be
either
$1 ne $tempitem
or
!($1 eq $tempitem)
or
not ($1 eq $tempitem)
In your version you first LOGICALY negate the $tempitem (which means
that if $tempitem is 0, 0.0, "0", "" or undef you get 1, in all other
cases you get an undef. And then you compare the 1 or undef with the
$1. Not likely to be what you meant.
> do an action;
> }else{
> do some other action;
> undef $tempitem;
>
> or
>
> If ($item =~ /^(\D+)(\d+)/ {)
> If ($1 eq defined(!$tempitem)) {
This is even more crazy :-)

>do an action;
> }else{
> do some other action;
> undef $tempitem;
Jenda
= [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


usage of Net::Telnet

2004-01-20 Thread Singh, Ajit p

Hi ,

I am trying to use the Net::Telnet module after installing in my solaris 2.8
machine.
But I am unable to get the output.

There is no error messages either.The program just exists.
Could you help me out on this please...

#!/usr/bin/perl -w
use Net::Telnet ();

$t = new Net::Telnet (Timeout => 1000,
  Port   => 8667);
$t->open("ss-ps.demon.net");

@output = $t->cmd("01244530112");
print @output;




regards,

Ajitpal Singh,
Wipro Technologies.
Finchley,London.
Tel:044 208 495 6317
Mobile:07900534143



-Original Message-
From: Jenda Krynicky [mailto:[EMAIL PROTECTED]
Sent: 20 January 2004 10:43
To: [EMAIL PROTECTED]
Subject: Re: Saying an item is empty


From: "Trina Espinoza" <[EMAIL PROTECTED]>
> I would like to know how  I would say if $item equals $tempitem OR if
> $item is empty(the variable is  a placeholder that has nothing in it),
> execute command. 

I'd revert the tests. First see whether it's empty, then whether it 
equals something:

if (!defined $item or $item eq $tempitem) {
do something

> Are either of these saying the above statement
> because I don't seem to be getting the expected results.
> 
> If ($item =~ /^(\D+)(\d+)/ {)
> If ($1 eq !$tempitem) {

I guess the capital "I"s were introduced by your mail client (I know 
some programs think they know better:-}

Anyway the
$1 eq !$tempitem
doesn't really make sense.

If you want to say "$1 does not equal to $tempitem" it should be 
either
$1 ne $tempitem
or
!($1 eq $tempitem)
or
not ($1 eq $tempitem)

In your version you first LOGICALY negate the $tempitem (which means 
that if $tempitem is 0, 0.0, "0", "" or undef you get 1, in all other 
cases you get an undef. And then you compare the 1 or undef with the 
$1. Not likely to be what you meant.

> do an action;
> }else{
> do some other action;
> undef $tempitem;
> 
> or
> 
> If ($item =~ /^(\D+)(\d+)/ {)
> If ($1 eq defined(!$tempitem)) {

This is even more crazy :-)

>do an action;
> }else{
> do some other action;
> undef $tempitem;


Jenda
= [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




RE: TRYING AGAIN (was: Net::Telnet)

2003-08-24 Thread Gupta, Sharad
Thanx a lot for replying.


I am telnetting from a windows machine to a unix machine.

Comparing the installations seems to be an idea. I'll also try from the XP machine.

Thanx again,


-Sharad
 
>-Original Message-
>From: Rob Dixon [mailto:[EMAIL PROTECTED]
>Sent: Sunday, August 24, 2003 5:16 AM
>To: [EMAIL PROTECTED]
>Subject: Re: TRYING AGAIN (was: Net::Telnet)
>
>
>
>Sharad Gupta wrote:
>>
>> Hi All,
>>
>> I have a small script like this:
>>
>> -----------
>> use strict;
>> use Net::Telnet;
>>
>> my $host = "Wilma";
>> my $username = "Foo";
>> my $pass = "Bar";
>>
>> my $s = Net::Telnet->new( Host=>$host,
>>   input_log => "input_log",
>>   dump_log => "dump_log",
>> );
>> $s->login($username,$pass);
>> $s->print("ls");
>> print $s->getlines();
>> 
>--
>>
>>
>> I can run this from a nix machine without any problems. But when
>> i try to run the same from a win2k machine it fails with 
>"read timed-out"
>> message. But the input_log file contains the correct output.
>>
>> Any ideas why getlines is timing out.
>
>Maybe.
>
>If you're Telnetting to a Windows machine then 'ls' isn't a 
>valid command.
>
>Otherwise you should check the differences between the Perl 
>installations
>on your Unix and Windows machine.
>
>Oh, and upgrade to Windows XP, which is about the best-behaved system
>that MS have come up with.
>
>HTH,
>
>Rob
>
>
>
>-- 
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
>
>


Re: TRYING AGAIN (was: Net::Telnet)

2003-08-24 Thread Rob Dixon

Sharad Gupta wrote:
>
> Hi All,
>
> I have a small script like this:
>
> ---
> use strict;
> use Net::Telnet;
>
> my $host = "Wilma";
> my $username = "Foo";
> my $pass = "Bar";
>
> my $s = Net::Telnet->new( Host=>$host,
>   input_log => "input_log",
>   dump_log => "dump_log",
> );
> $s->login($username,$pass);
> $s->print("ls");
> print $s->getlines();
> --
>
>
> I can run this from a nix machine without any problems. But when
> i try to run the same from a win2k machine it fails with "read timed-out"
> message. But the input_log file contains the correct output.
>
> Any ideas why getlines is timing out.

Maybe.

If you're Telnetting to a Windows machine then 'ls' isn't a valid command.

Otherwise you should check the differences between the Perl installations
on your Unix and Windows machine.

Oh, and upgrade to Windows XP, which is about the best-behaved system
that MS have come up with.

HTH,

Rob



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



TRYING AGAIN (was: Net::Telnet)

2003-08-23 Thread Gupta, Sharad
I am sure somebody would have a magical touch for me.

-Sharad

-Original Message-
From: Gupta, Sharad 
Sent: Saturday, August 16, 2003 9:03 PM
To: [EMAIL PROTECTED]
Subject: Net::Telnet



Hi All,

I have a small script like this:

---
use strict;
use Net::Telnet;

my $host = "Wilma";
my $username = "Foo";
my $pass = "Bar";

my $s = Net::Telnet->new( Host=>$host,
  input_log => "input_log",
  dump_log => "dump_log",
);
$s->login($username,$pass);
$s->print("ls");
print $s->getlines();
--


I can run this from a nix machine without any problems. But when i try to run the same 
from a win2k machine it fails with 
"read timed-out" message. But the input_log file contains the correct output. Any 
ideas why getlines is timing out.



Thanx for help,
-Sharad 




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



Net::Telnet

2003-08-16 Thread Gupta, Sharad

Hi All,

I have a small script like this:

---
use strict;
use Net::Telnet;

my $host = "Wilma";
my $username = "Foo";
my $pass = "Bar";

my $s = Net::Telnet->new( Host=>$host,
  input_log => "input_log",
  dump_log => "dump_log",
);
$s->login($username,$pass);
$s->print("ls");
print $s->getlines();
--


I can run this from a nix machine without any problems. But when i try to run the same 
from a win2k machine it fails with 
"read timed-out" message. But the input_log file contains the correct output. Any 
ideas why getlines is timing out.



Thanx for help,
-Sharad 




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



Re: Net::Telnet - Variable won't change

2003-08-14 Thread Jeff Westman

--- SilverFox <[EMAIL PROTECTED]> wrote:
> Jeff Westman wrote:
> 
> > 
> > --- SilverFox <[EMAIL PROTECTED]> wrote:
> >> Hey can someone help me figure out why the value of $file_exists won't
> >> change even when the file is mssing Thx.
> >> 
> >> #!/usr/bin/perl -w
> >> $out="/home/laptop/scripts/perl/logs/resetmf.log";
> >> open OUT, ">>$out" or die "Unable to open $out :$!";
> >> 
> >> @site=("Machine1","Machine2");
> >> #telnet
> >> use Net::Telnet;
> >> $t = new Net::Telnet (Timeout=>10,
> >> Errmode=>'die',
> >> Prompt=>'/\$ $/i');
> >> foreach (@site) {
> >> $t->open($_);
> >> $t->login('username','passwd');
> >> print OUT scalar(localtime), " Conn EST: $_.\n";
> >> 
> >> 
> >> $dir="pf/working/output/Channel_status";
> >> @newdir=("/Machine1/$dir","/Machine2/$dir","/Machine9/$dir");
> >> 
> >> for($x=0; $x <= $#newdir; $x++) {
> >> 
> >> 
> >> $file_exists = $t->cmd ("perl -e 'print 1 if (-s \"$newdir[$x]\")'") or
> >> warn "Unable to execute: $!\n";
> >> 
> >> if ($file_exists) {
> >> print "Found it\n";
> >> }else{
> >>print "File Missing\n";
> >> 
> >> }
> >>}
> >>  }
> >> 
> > 
> > When I tried to run your cmd/perl line simply to test that part, I got:
> > 
> >   $file_exists = $t->cmd ("ksh: syntax error: `(' unexpected
> > 
> > Alternatively, you might try something simpler like:
> > 
> >   $file_exists = $t->cmd("test -f $newdir[$x] && print 1 || print 0");
> > 
> > 
> > 
> > -JW
> > 
> > 
> hmmmI'm still getting the same results. Think it have something to do 
> with my shell (/usr/bin/sh). 


First, see if you can even do that shell test actually logged into that box,
see what it returns.

Second, I've had problems with telnet.pm -- kind of flakey at times, so you
might try this instead:

$file_exists = sprintf("%s", 
$t->cmd("test -f $newdir[$x] && print 1 || print 0") );

That did the trick for me when I didn't get teh right results back.


JW


__
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com

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



Re: Net::Telnet - Variable won't change

2003-08-14 Thread Jeff Westman

--- SilverFox <[EMAIL PROTECTED]> wrote:
> Hey can someone help me figure out why the value of $file_exists won't 
> change even when the file is mssing Thx.
> 
> #!/usr/bin/perl -w
> $out="/home/laptop/scripts/perl/logs/resetmf.log";
> open OUT, ">>$out" or die "Unable to open $out :$!";
> 
> @site=("Machine1","Machine2");
> #telnet
> use Net::Telnet;
> $t = new Net::Telnet (Timeout=>10,
> Errmode=>'die',
> Prompt=>'/\$ $/i');
> foreach (@site) {
> $t->open($_);
> $t->login('username','passwd');
> print OUT scalar(localtime), " Conn EST: $_.\n";
> 
> 
> $dir="pf/working/output/Channel_status";
> @newdir=("/Machine1/$dir","/Machine2/$dir","/Machine9/$dir");
> 
> for($x=0; $x <= $#newdir; $x++) {
> 
> 
> $file_exists = $t->cmd ("perl -e 'print 1 if (-s \"$newdir[$x]\")'") or 
> warn "Unable to execute: $!\n";
> 
> if ($file_exists) {
> print "Found it\n";
> }else{
>print "File Missing\n";
> 
> }
>}
>  }
> 

When I tried to run your cmd/perl line simply to test that part, I got:

  $file_exists = $t->cmd ("ksh: syntax error: `(' unexpected

Alternatively, you might try something simpler like:

  $file_exists = $t->cmd("test -f $newdir[$x] && print 1 || print 0");



-JW



__
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com

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



Net::Telnet

2003-08-14 Thread SilverFox
hey anyone know how to check if a file exists using the Telnet module?

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



Re: Net::Telnet - Variable won't change

2003-08-14 Thread SilverFox
Jeff Westman wrote:

> 
> --- SilverFox <[EMAIL PROTECTED]> wrote:
>> Hey can someone help me figure out why the value of $file_exists won't
>> change even when the file is mssing Thx.
>> 
>> #!/usr/bin/perl -w
>> $out="/home/laptop/scripts/perl/logs/resetmf.log";
>> open OUT, ">>$out" or die "Unable to open $out :$!";
>> 
>> @site=("Machine1","Machine2");
>> #telnet
>> use Net::Telnet;
>> $t = new Net::Telnet (Timeout=>10,
>> Errmode=>'die',
>> Prompt=>'/\$ $/i');
>> foreach (@site) {
>> $t->open($_);
>> $t->login('username','passwd');
>> print OUT scalar(localtime), " Conn EST: $_.\n";
>> 
>> 
>> $dir="pf/working/output/Channel_status";
>> @newdir=("/Machine1/$dir","/Machine2/$dir","/Machine9/$dir");
>> 
>> for($x=0; $x <= $#newdir; $x++) {
>> 
>> 
>> $file_exists = $t->cmd ("perl -e 'print 1 if (-s \"$newdir[$x]\")'") or
>> warn "Unable to execute: $!\n";
>> 
>> if ($file_exists) {
>> print "Found it\n";
>> }else{
>>print "File Missing\n";
>> 
>> }
>>}
>>  }
>> 
> 
> When I tried to run your cmd/perl line simply to test that part, I got:
> 
>   $file_exists = $t->cmd ("ksh: syntax error: `(' unexpected
> 
> Alternatively, you might try something simpler like:
> 
>   $file_exists = $t->cmd("test -f $newdir[$x] && print 1 || print 0");
> 
> 
> 
> -JW
> 
> 
hmmmI'm still getting the same results. Think it have something to do 
with my shell (/usr/bin/sh). 

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



  1   2   >