You can subscribe to this list here.
2000 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(1) |
Sep
(1) |
Oct
(1) |
Nov
(26) |
Dec
(7) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2001 |
Jan
(5) |
Feb
(3) |
Mar
(11) |
Apr
(10) |
May
(2) |
Jun
(5) |
Jul
(13) |
Aug
(2) |
Sep
(3) |
Oct
(10) |
Nov
(18) |
Dec
(29) |
2002 |
Jan
(12) |
Feb
(14) |
Mar
(73) |
Apr
(28) |
May
(21) |
Jun
(39) |
Jul
(40) |
Aug
(42) |
Sep
(20) |
Oct
(4) |
Nov
(9) |
Dec
(18) |
2003 |
Jan
(2) |
Feb
(8) |
Mar
(6) |
Apr
(24) |
May
(24) |
Jun
(14) |
Jul
(16) |
Aug
(36) |
Sep
(34) |
Oct
(23) |
Nov
(4) |
Dec
(15) |
2004 |
Jan
(6) |
Feb
(13) |
Mar
(7) |
Apr
(5) |
May
(11) |
Jun
(5) |
Jul
(4) |
Aug
|
Sep
(2) |
Oct
(16) |
Nov
(4) |
Dec
(9) |
2005 |
Jan
(2) |
Feb
(1) |
Mar
(3) |
Apr
(10) |
May
(5) |
Jun
(13) |
Jul
(3) |
Aug
|
Sep
(7) |
Oct
(5) |
Nov
(1) |
Dec
(9) |
2006 |
Jan
|
Feb
(10) |
Mar
(22) |
Apr
(14) |
May
(5) |
Jun
(4) |
Jul
(19) |
Aug
(7) |
Sep
(16) |
Oct
(4) |
Nov
(1) |
Dec
(16) |
2007 |
Jan
(17) |
Feb
|
Mar
(35) |
Apr
(5) |
May
(20) |
Jun
(11) |
Jul
(33) |
Aug
(3) |
Sep
(2) |
Oct
(11) |
Nov
(23) |
Dec
(5) |
2008 |
Jan
(10) |
Feb
(9) |
Mar
|
Apr
(6) |
May
(8) |
Jun
(7) |
Jul
|
Aug
(3) |
Sep
(2) |
Oct
(1) |
Nov
|
Dec
(20) |
2009 |
Jan
(8) |
Feb
(8) |
Mar
(3) |
Apr
(8) |
May
(2) |
Jun
(11) |
Jul
(2) |
Aug
|
Sep
(3) |
Oct
(1) |
Nov
(7) |
Dec
(4) |
2010 |
Jan
(2) |
Feb
(1) |
Mar
(3) |
Apr
|
May
(2) |
Jun
(2) |
Jul
(7) |
Aug
(3) |
Sep
(7) |
Oct
(2) |
Nov
(1) |
Dec
(4) |
2011 |
Jan
(4) |
Feb
(5) |
Mar
|
Apr
(3) |
May
(2) |
Jun
|
Jul
(6) |
Aug
|
Sep
|
Oct
(6) |
Nov
|
Dec
|
2012 |
Jan
|
Feb
(1) |
Mar
|
Apr
(3) |
May
|
Jun
|
Jul
(2) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2013 |
Jan
|
Feb
(1) |
Mar
|
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
(5) |
Oct
|
Nov
|
Dec
|
2014 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(2) |
Aug
(7) |
Sep
(2) |
Oct
|
Nov
|
Dec
|
2015 |
Jan
|
Feb
|
Mar
(30) |
Apr
(10) |
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2017 |
Jan
|
Feb
|
Mar
(12) |
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(1) |
Dec
(1) |
2018 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(2) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2022 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(1) |
Dec
|
2024 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(1) |
From: Noah <ad...@en...> - 2007-10-24 17:23:14
|
Hi there, It's been a while since I've coded in perl/expect. I am finding that when sending the "request snmp spoof-trap $trap" in the for loop that the command is sent without waiting for the prompt. In fact they are sent as fast as they can be. I am trying to figure out why that is happening. since expect is not waiting for the prompt the commands get truncated and CLI errors result, etc. What am I doing wrong? Cheers, Noah --- snip --- #!/usr/bin/perl # use Expect; #use Expect::Simple; # #--- ENSURE TO HAVE SUFFICIENT COMMAND LINE ARGUMENTS ! ----------------------# # if ( $#ARGV != 2 ) { printf("USAGE: $0 <host> <user> <pw>\n"); exit(-1); } $host = shift; $user = shift; $pw = shift; # #--- CONFIGURATION -----------------------------------------------------------# # $cmd = "ssh -l $user $host"; $prompt = "[Pp]assword"; $data_file = "traps.txt"; open (DAT, $data_file) || die("Could not open file!"); @raw_data=<DAT>; close (DAT); # #--- START SSH LOGIN SEQUENCE ! ----------------------------------------------# # $exp = new Expect(); $exp->raw_pty(0); $exp->spawn($cmd); # #--- LOGIN AND INTERACT ! ----------------------------------------------------# # $exp->expect(10000, [ $prompt => sub { $_[0]->send("$pw\n"); } ]); $prompt = "$user\@$host>"; $exp->expect(10000, [ $prompt => sub { $_[0]->send("set cli screen-length 0\n"); } ]); $x = 2; foreach $trap (@raw_data) { $prompt = "$user\@$host>"; $exp->expect(10000, [ $prompt => sub { $_[0]->send("request snmp spoof-trap $trap\n"); } ]); $x++; } $exp->interact(); print "\n\n"; $exp->soft_close(); |
From: Philip M. v. R. <po...@po...> - 2007-10-04 17:03:05
|
Hi Bryan. Thanks so much for the quick reply. Due to the threading model/= hierarchy I'm using (main_thread->boss_threads->worker_threads), I'm establ= ishing the connection to the load balancers in the main thread to try and a= void any issues with thread-safety. The boss threads don't return until al= l of it's worker thread groups is complete, so I'm not closing the Expect o= bjects after the first group is complete. That may be part of the problem,= but it seems like they shouldn't interfere since the worker threads aren't= using the Expect objects at all. I'll give your suggestion a try. In the= meantime, I've used Net::Telnet and a slightly modified version of the exa= mple in the docs to establish the ssh connection (I also needed to fix a bu= g in the example). I just threw it in a simple module:=0A=0A=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=0Apackage MySSH;=0A=0Arequire Exporter;=0A=0Ause strict;=0Ause= IO::Pty;=0Ause Net::Telnet;=0A=0Aour @ISA =3D ("Exporter");=0Aour @EXPORT = =3D qw(get_connection);=0A=0A=0Asub get_connection {=0A my ($pty, $s= sh, @lines);=0A my $host =3D shift;=0A my $user =3D shift;=0A= my $password =3D shift;=0A my $prompt =3D '/ # /';=0A=0A = ## Start ssh program.=0A $pty =3D &spawn("ssh", "-l", $user, $ho= st); # spawn() defined below=0A if ($pty =3D~ /ERROR/i) {=0A = return $pty;=0A }=0A=0A ## Create a Net::Telnet obje= ct to perform I/O on ssh's tty.=0A use Net::Telnet;=0A $ssh = =3D new Net::Telnet (-fhopen =3D> $pty,=0A -= prompt =3D> $prompt,=0A -telnetmode =3D> 0,= =0A -cmd_remove_mode =3D> 1,=0A = -output_record_separator =3D> "\r");=0A=0A ## Log= in to remote host.=0A $ssh->waitfor(-match =3D> '/Password: ?$/i',= =0A -errmode =3D> "return")=0A or return "E= RROR: problem connecting to host: ", $ssh->lastline;=0A $ssh->print(= $password);=0A $ssh->waitfor(-match =3D> $ssh->prompt,=0A = -errmode =3D> "return")=0A or return "ERROR: login fa= iled: ", $ssh->lastline;=0A=0A return $ssh;=0A}=0A=0Asub spawn {=0A = my(@cmd) =3D @_;=0A my($pid, $pty, $tty, $tty_fd);=0A=0A = ## Create a new pseudo terminal.=0A use IO::Pty ();=0A $pt= y =3D new IO::Pty=0A or return "ERROR: $!";=0A=0A ## Exec= ute the program in another process.=0A unless ($pid =3D fork) { # c= hild process=0A return "ERROR: problem spawning program: $!\n" u= nless defined $pid;=0A=0A ## Disassociate process from existing = controlling terminal.=0A use POSIX ();=0A POSIX::sets= id=0A or return "ERROR: setsid failed: $!";=0A=0A = ## Associate process with a new controlling terminal.=0A $tty = =3D $pty->slave;=0A ## This line is missing in the Net::Telnet= docs - it won't work otherwise=0A $pty->make_slave_controlling_= terminal();=0A $tty_fd =3D $tty->fileno;=0A close $pt= y;=0A=0A ## Make stdio use the new controlling terminal.=0A = open STDIN, "<&$tty_fd" or die $!;=0A open STDOUT, ">&$tt= y_fd" or die $!;=0A open STDERR, ">&STDOUT" or die $!;=0A = close $tty;=0A=0A ## Execute requested program.=0A = exec @cmd=0A or return "ERROR: problem executing $cmd[0]\= n";=0A } # end child process=0A=0A $pty;=0A} # end sub spawn= =0A=0A1;=0A=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=0AThen I can just call get_connecti= on($server,$user,$password) in the main thread and pass the returned Net::T= elnet object around without closing the connection after each worker thread= group is complete. This has been working so far. =0A=0AOne thing that ha= s not been resolved in any solution I've tried is the "Scalars leaked: 2" w= arnings. I've read that these are relatively harmless and there is even so= me mention that this is a bug in Perl 5.8.x. Is there any way to suppress = these? I've commented out warnings and diagnostics, but they still show up= .=0A=0AThanks again for the help.=0A=0A-Phil=0A=0A----- Original Message --= --=0AFrom: Bryan Bueter <br...@bu...>=0ATo: POMvR <pomvr@pobox.c= om>=0ACc: exp...@li...=0ASent: Thursday, Octobe= r 4, 2007 6:57:14 AM=0ASubject: Re: [Expectperl-discuss] Another threading = question=0A=0A=0A>=0A> Hey folks. I've really appreciated the posts in thi= s forum, as they have=0A> gotten me past the initial roadblocks to getting = Expect to work in a=0A> threaded PERL application. Unfortunately, I've hit= a bit of a snag and I=0A> thought I'd post the problem here to see if anyo= ne's experienced the same=0A> type of issue. Following what's been suggest= ed here, I'm creating my=0A> initial Expect objects in the main thread and = establishing ssh connections=0A> to the load balancers I need. I'm passing= these objects to a handful of=0A> boss threads, which first loop through a= set of servers to remove them=0A> from=0A> the load balancer via Expect. = Each boss thread then creates a pool of=0A> child=0A> threads that issue co= mmands against this same set of servers and doesn't=0A> use=0A> Expect (or = the connection object). The code works great on the first set=0A> of=0A> s= ervers, but after I join the first group of threads and they finish, the=0A= > second set is returning undefined for all the expect(...) calls. What=0A= > makes=0A> this so strange is that if I turn on debugging for Expect, it w= orks fine=0A> (although it floods STDOUT). I've tried a number of things t= o try and=0A> solve=0A> the problem (flushing STDOUT, calling clear_accum()= , turning on warnings=0A> and=0A> diagnostics). The only hint of what's go= ing on came through diagnostics,=0A> which throws the following error when = the problems start to occur:=0A>=0A> print() on closed filehandle GEN0 at= =0A> /usr/lib/perl5/5.8.0/i386-linux-thread-multi/IO/Handle.pm line= =0A> 395,=0A> <STDIN> line 3 (#1)=0A> (W closed) The filehandle you're = printing on got itself closed=0A> sometime=0A> before now. Check your = control flow.=0A>=0A> Here's a simplified version of the code from the boss= thread that appears=0A> to=0A> be causing problems:=0A>=0A> # First remove= all the servers from the load balancer pool=0A> foreach my $serv (@server_= stack) {=0A> $result =3D &run_command($expect_connection,"disable $serv= ");=0A> }=0A> # Run some commands against this set of servers now that they= 're out of=0A> the=0A> pool=0A> my @threads =3D ();=0A> while (@server_stac= k) {=0A> my $server =3D pop(@server_stack);=0A> push @threa= ds, threads->new(\&shutdown_server,$server);=0A> }=0A> foreach my $thr (@th= reads) {=0A> @return_vals =3D (@return_vals, $thr->join());=0A> }=0A> f= oreach my $thr (@threads) {=0A> undef $thr;=0A> }=0A>=0A> Since I'm usi= ng PERL 5.8.0, I'm undef'ing the threads once they are=0A> finished, since = there were some issues with this in 5.8.0. This code=0A> block=0A> runs fi= ne the first time, but as soon as I send it a new @server_stack,=0A> the=0A= > calls to &run_command no longer work. Here's what run_command looks like= :=0A>=0A> sub run_command {=0A> my($proc, $command) =3D @_;=0A> my = $timeout =3D 6;=0A> $proc->raw_pty(1);=0A> $proc->log_stdout(0);=0A= > $proc->log_file("temp.log");=0A> $proc->debug(0);=0A> $proc->= send("$command\r");=0A> my $i =3D $proc->expect($timeout, "-re", " # ")= ;=0A> if (!(defined $i)) {=0A> return "ERROR: no response to co= mmand!\n";=0A> }=0A> return $proc->before();=0A> }=0A>=0A> However,= if I set $proc->debug(4), it works fine, albeit a bit ugly to=0A> watch. = It almost seems like something is closing the filehandle that the=0A> Expec= t connection object is using after the first thread group finishes,=0A> eve= n though the thread group isn't even operating on the connection=0A> object= .=0A> I apologize for only posting snippets, but there is too much code to = post=0A> otherwise. I'm getting this system upgraded to PERL 5.8.8, but it= 's not=0A> going to be anytime soon, so I'm trying to make this work with w= hat I've=0A> got.=0A>=0A> If anyone has experienced something similar or ha= s an idea what might fix=0A> this, it would be much appreciated. I've been= pulling my hair out on this=0A> one for a while now. Thanks for listening= .=0A>=0A> -Phil=0A> --=0A=0AI've had the same problem, and my fix was the u= ndef piece you already=0Ahave. However, I'm not sure what state the expect= objects are in when you=0Astart your new group of threads.=0A=0AWhat has w= orked for me is this: I setup expect objects on a group of=0Aservers first,= then exec, then close the expect objects, and finally join=0Athem. Next I= move on to the next group of servers and do the same.=0A=0AThis is my basi= c routine:=0A=0A=0Amy $max_threads =3D 4;=0Awhile (@servers || @server_stac= k) {=0A my $host =3D shift @servers;=0A=0A my $exp =3D function_to_setup_= expect($host) || next;=0A push(@server_stack, $host);=0A=0A if (@server_s= tack =3D=3D $max_threads || !@servers) {=0A foreach my $server (@server_= stack) {=0A push @threads, threads->new(\&shutdown_server,$server);=0A= }=0A foreach my $thr (@threads) {=0A @return_vals =3D (@return_= vals, $thr->join());=0A undef $thr;=0A }=0A @server_stack =3D ()= ;=0A @threads =3D ();=0A }=0A}=0A=0ANot saying there isnt something els= e wrong here, but like i said, this=0Amethod works for me in all 5.8.0 vers= ions.=0A=0AHope that helps.=0A=0A=0ABryan=0Ahttp://sourceforge.net/projects= /rover=0A=0A=0A=0A=0A=0A=0A=0A=0A =0A________________________________= ____________________________________________________=0AMoody friends. Drama= queens. Your life? Nope! - their life, your story. Play Sims Stories at Ya= hoo! Games.=0Ahttp://sims.yahoo.com/ |
From: Bryan B. <br...@bu...> - 2007-10-04 13:57:20
|
> > Hey folks. I've really appreciated the posts in this forum, as they have > gotten me past the initial roadblocks to getting Expect to work in a > threaded PERL application. Unfortunately, I've hit a bit of a snag and I > thought I'd post the problem here to see if anyone's experienced the same > type of issue. Following what's been suggested here, I'm creating my > initial Expect objects in the main thread and establishing ssh connections > to the load balancers I need. I'm passing these objects to a handful of > boss threads, which first loop through a set of servers to remove them > from > the load balancer via Expect. Each boss thread then creates a pool of > child > threads that issue commands against this same set of servers and doesn't > use > Expect (or the connection object). The code works great on the first set > of > servers, but after I join the first group of threads and they finish, the > second set is returning undefined for all the expect(...) calls. What > makes > this so strange is that if I turn on debugging for Expect, it works fine > (although it floods STDOUT). I've tried a number of things to try and > solve > the problem (flushing STDOUT, calling clear_accum(), turning on warnings > and > diagnostics). The only hint of what's going on came through diagnostics, > which throws the following error when the problems start to occur: > > print() on closed filehandle GEN0 at > /usr/lib/perl5/5.8.0/i386-linux-thread-multi/IO/Handle.pm line > 395, > <STDIN> line 3 (#1) > (W closed) The filehandle you're printing on got itself closed > sometime > before now. Check your control flow. > > Here's a simplified version of the code from the boss thread that appears > to > be causing problems: > > # First remove all the servers from the load balancer pool > foreach my $serv (@server_stack) { > $result = &run_command($expect_connection,"disable $serv"); > } > # Run some commands against this set of servers now that they're out of > the > pool > my @threads = (); > while (@server_stack) { > my $server = pop(@server_stack); > push @threads, threads->new(\&shutdown_server,$server); > } > foreach my $thr (@threads) { > @return_vals = (@return_vals, $thr->join()); > } > foreach my $thr (@threads) { > undef $thr; > } > > Since I'm using PERL 5.8.0, I'm undef'ing the threads once they are > finished, since there were some issues with this in 5.8.0. This code > block > runs fine the first time, but as soon as I send it a new @server_stack, > the > calls to &run_command no longer work. Here's what run_command looks like: > > sub run_command { > my($proc, $command) = @_; > my $timeout = 6; > $proc->raw_pty(1); > $proc->log_stdout(0); > $proc->log_file("temp.log"); > $proc->debug(0); > $proc->send("$command\r"); > my $i = $proc->expect($timeout, "-re", " # "); > if (!(defined $i)) { > return "ERROR: no response to command!\n"; > } > return $proc->before(); > } > > However, if I set $proc->debug(4), it works fine, albeit a bit ugly to > watch. It almost seems like something is closing the filehandle that the > Expect connection object is using after the first thread group finishes, > even though the thread group isn't even operating on the connection > object. > I apologize for only posting snippets, but there is too much code to post > otherwise. I'm getting this system upgraded to PERL 5.8.8, but it's not > going to be anytime soon, so I'm trying to make this work with what I've > got. > > If anyone has experienced something similar or has an idea what might fix > this, it would be much appreciated. I've been pulling my hair out on this > one for a while now. Thanks for listening. > > -Phil > -- I've had the same problem, and my fix was the undef piece you already have. However, I'm not sure what state the expect objects are in when you start your new group of threads. What has worked for me is this: I setup expect objects on a group of servers first, then exec, then close the expect objects, and finally join them. Next I move on to the next group of servers and do the same. This is my basic routine: my $max_threads = 4; while (@servers || @server_stack) { my $host = shift @servers; my $exp = function_to_setup_expect($host) || next; push(@server_stack, $host); if (@server_stack == $max_threads || !@servers) { foreach my $server (@server_stack) { push @threads, threads->new(\&shutdown_server,$server); } foreach my $thr (@threads) { @return_vals = (@return_vals, $thr->join()); undef $thr; } @server_stack = (); @threads = (); } } Not saying there isnt something else wrong here, but like i said, this method works for me in all 5.8.0 versions. Hope that helps. Bryan http://sourceforge.net/projects/rover |
From: POMvR <po...@po...> - 2007-10-03 04:56:39
|
Hey folks. I've really appreciated the posts in this forum, as they have gotten me past the initial roadblocks to getting Expect to work in a threaded PERL application. Unfortunately, I've hit a bit of a snag and I thought I'd post the problem here to see if anyone's experienced the same type of issue. Following what's been suggested here, I'm creating my initial Expect objects in the main thread and establishing ssh connections to the load balancers I need. I'm passing these objects to a handful of boss threads, which first loop through a set of servers to remove them from the load balancer via Expect. Each boss thread then creates a pool of child threads that issue commands against this same set of servers and doesn't use Expect (or the connection object). The code works great on the first set of servers, but after I join the first group of threads and they finish, the second set is returning undefined for all the expect(...) calls. What makes this so strange is that if I turn on debugging for Expect, it works fine (although it floods STDOUT). I've tried a number of things to try and solve the problem (flushing STDOUT, calling clear_accum(), turning on warnings and diagnostics). The only hint of what's going on came through diagnostics, which throws the following error when the problems start to occur: print() on closed filehandle GEN0 at /usr/lib/perl5/5.8.0/i386-linux-thread-multi/IO/Handle.pm line 395, <STDIN> line 3 (#1) (W closed) The filehandle you're printing on got itself closed sometime before now. Check your control flow. Here's a simplified version of the code from the boss thread that appears to be causing problems: # First remove all the servers from the load balancer pool foreach my $serv (@server_stack) { $result = &run_command($expect_connection,"disable $serv"); } # Run some commands against this set of servers now that they're out of the pool my @threads = (); while (@server_stack) { my $server = pop(@server_stack); push @threads, threads->new(\&shutdown_server,$server); } foreach my $thr (@threads) { @return_vals = (@return_vals, $thr->join()); } foreach my $thr (@threads) { undef $thr; } Since I'm using PERL 5.8.0, I'm undef'ing the threads once they are finished, since there were some issues with this in 5.8.0. This code block runs fine the first time, but as soon as I send it a new @server_stack, the calls to &run_command no longer work. Here's what run_command looks like: sub run_command { my($proc, $command) = @_; my $timeout = 6; $proc->raw_pty(1); $proc->log_stdout(0); $proc->log_file("temp.log"); $proc->debug(0); $proc->send("$command\r"); my $i = $proc->expect($timeout, "-re", " # "); if (!(defined $i)) { return "ERROR: no response to command!\n"; } return $proc->before(); } However, if I set $proc->debug(4), it works fine, albeit a bit ugly to watch. It almost seems like something is closing the filehandle that the Expect connection object is using after the first thread group finishes, even though the thread group isn't even operating on the connection object. I apologize for only posting snippets, but there is too much code to post otherwise. I'm getting this system upgraded to PERL 5.8.8, but it's not going to be anytime soon, so I'm trying to make this work with what I've got. If anyone has experienced something similar or has an idea what might fix this, it would be much appreciated. I've been pulling my hair out on this one for a while now. Thanks for listening. -Phil -- View this message in context: http://www.nabble.com/Another-threading-question-tf4559826.html#a13012890 Sent from the Perl - Expectperl-Discuss mailing list archive at Nabble.com. |
From: Roland G. <rgi...@cp...> - 2007-09-27 10:57:47
|
Take a look at vec(). perldoc -f vec And how exactly is this related to Expect? Roland On 9/26/07, rag84dec <rag...@gm...> wrote: > > Hi, > > I need to shift 32 bits in perl. > > Like $t=0xe1; > $r=$t<<32; > > but it is not working since scalar can hold 32 bits ...can u tell me how to > make it work??? > > i want to send this to postmessage($hnd,$msg,0,$r); > > $r should contain yx position....x-32 bit y 32-bits > > how to do???? > > > -- > View this message in context: http://www.nabble.com/left-shift-problem-tf4521525.html#a12898474 > Sent from the Perl - Expectperl-Discuss mailing list archive at Nabble.com. > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2005. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > Expectperl-discuss mailing list > Exp...@li... > https://lists.sourceforge.net/lists/listinfo/expectperl-discuss > |
From: rag84dec <rag...@gm...> - 2007-09-26 10:57:30
|
Hi, I need to shift 32 bits in perl. Like $t=0xe1; $r=$t<<32; but it is not working since scalar can hold 32 bits ...can u tell me how to make it work??? i want to send this to postmessage($hnd,$msg,0,$r); $r should contain yx position....x-32 bit y 32-bits how to do???? -- View this message in context: http://www.nabble.com/left-shift-problem-tf4521525.html#a12898474 Sent from the Perl - Expectperl-Discuss mailing list archive at Nabble.com. |
From: Bruno N. <bn...@gm...> - 2007-08-20 15:07:01
|
Hello guys, I just wanted to let you know that my module Net::SSH::Expect, an ssh wrapper that uses Expect to start an ssh process and login and execute commands via ssh is already working. its documentation can be accessed on: http://cpan.uwinnipeg.ca/htdocs/Net-SSH-Expect/Net/SSH/Expect.html My module offers interesting methods to read from the spawned process's input stream, like peek(), read_line(), read_all() and eat(), that make reading much simpler and free from regular expressions. Maybe they should be incorporated to the Expect module itself since they could be used to read from any process. Best regards, bruno |
From: Bruno N. <bn...@gm...> - 2007-08-04 00:24:30
|
Hello guys, I'd like to let you know that i published on CPAN the last version of my module BNEGRAO/Net-SSH-Expect-1.02.tar.gz It's a module to logon via ssh and exec commands on the ssh server. It works with or without password-based authentication. It's still beta and its documentation is not completed yet. Regards, bruno |
From: Austin S. <te...@of...> - 2007-08-01 04:55:33
|
On Tue, Jul 31, 2007 at 08:02:21PM -0300, Bruno Negrao wrote: > Hello all, > > Can you tell me why isn't the expect(1, '-re', $string) bellow matching > successfully? > You are putting in a bizarre regular expression and then expecting perl to have it match itself. That doesn't make any sense, let alone work. Maybe you don't want the string to be treated as a regular expression? Austin > I put in color RED the debug message showing that the pattern in $string is > exactly what expect has on it's accumulator. > > So why isn't it matching? There are some "\n" in the pattern, can it be a > problem? > > > Starting EXPECT pattern matching... > Expect::expect('Expect=GLOB(0x8064a020)',0,'-re',' PID TTY > TIME CMD\x{a} 9724 ? 00:00:00 bash\x{a} 988...') called at > /home/brunonz/Net-SSH-Expect/lib/Net/SSH/Expect.pm line 239 > Net::SSH::Expect::eat('Net::SSH::Expect=ARRAY(0x80173ce0)',' PID > TTY TIME CMD\x{a} 9724 ? 00:00:00 bash\x{a} 988...') called > at /home/brunonz/Net-SSH-Expect/lib/Net/SSH/Expect.pm line 270 > Net::SSH::Expect::readAll('Net::SSH::Expect=ARRAY(0x80173ce0)',1) > called at /home/brunonz/Net-SSH-Expect/lib/Net/SSH/Expect.pm line 289 > Net::SSH::Expect::exec('Net::SSH::Expect=ARRAY(0x80173ce0)','ps',1) > called at ./wshell line 66 > eval {...} called at ./wshell line 65 > spawn id(3): list of patterns: > #1: -re ` PID TTY TIME CMD\n 9724 ? 00:00:00 bash\n 9888 > ? 00:00:00 bash\n12978 ? 00:00:00 bash\n13075 ? > 00:00:00 ps\n' > > > spawn id(3): Does ` PID TTY TIME CMD\n 9724 ? 00:00:00 > bash\n 9888 ? 00:00:00 bash\n12978 ? 00:00:00 bash\n13075 > ? 00:00:00 ps\n' > > match: > pattern #1: -re ` PID TTY TIME CMD\n 9724 ? 00:00:00 > bash\n 9888 ? 00:00:00 bash\n12978 ? 00:00:00 bash\n13075 > ? 00:00:00 ps\n'? No. > > > > > Best regards, > > bruno > > > !DSPAM:46afbdd5314191222944467! > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Splunk Inc. > Still grepping through log files to find problems? Stop. > Now Search log events and configuration files using AJAX and a browser. > Download your FREE copy of Splunk now >> http://get.splunk.com/ > > !DSPAM:46afbdd5314191222944467! > _______________________________________________ > Expectperl-discuss mailing list > Exp...@li... > https://lists.sourceforge.net/lists/listinfo/expectperl-discuss > > > !DSPAM:46afbdd5314191222944467! |
From: Bruno N. <bn...@gm...> - 2007-07-31 23:02:26
|
Hello all, Can you tell me why isn't the expect(1, '-re', $string) bellow matching successfully? I put in color RED the debug message showing that the pattern in $string is exactly what expect has on it's accumulator. So why isn't it matching? There are some "\n" in the pattern, can it be a problem? Starting EXPECT pattern matching... Expect::expect('Expect=GLOB(0x8064a020)',0,'-re',' PID TTY TIME CMD\x{a} 9724 ? 00:00:00 bash\x{a} 988...') called at /home/brunonz/Net-SSH-Expect/lib/Net/SSH/Expect.pm line 239 Net::SSH::Expect::eat('Net::SSH::Expect=ARRAY(0x80173ce0)',' PID TTY TIME CMD\x{a} 9724 ? 00:00:00 bash\x{a} 988...') called at /home/brunonz/Net-SSH-Expect/lib/Net/SSH/Expect.pm line 270 Net::SSH::Expect::readAll('Net::SSH::Expect=ARRAY(0x80173ce0)',1) called at /home/brunonz/Net-SSH-Expect/lib/Net/SSH/Expect.pm line 289 Net::SSH::Expect::exec('Net::SSH::Expect=ARRAY(0x80173ce0)','ps',1) called at ./wshell line 66 eval {...} called at ./wshell line 65 spawn id(3): list of patterns: #1: -re ` PID TTY TIME CMD\n 9724 ? 00:00:00 bash\n 9888 ? 00:00:00 bash\n12978 ? 00:00:00 bash\n13075 ? 00:00:00 ps\n' spawn id(3): Does ` PID TTY TIME CMD\n 9724 ? 00:00:00 bash\n 9888 ? 00:00:00 bash\n12978 ? 00:00:00 bash\n13075 ? 00:00:00 ps\n' match: pattern #1: -re ` PID TTY TIME CMD\n 9724 ? 00:00:00 bash\n 9888 ? 00:00:00 bash\n12978 ? 00:00:00 bash\n13075 ? 00:00:00 ps\n'? No. Best regards, bruno |
From: Ken I. <fn...@ua...> - 2007-07-26 16:53:11
|
On Thu, Jul 26, 2007 at 11:08:11AM -0400, Chuck Son wrote: > It appears that whenever I use send(), the next expect() will read the > previous line again and thus causing the send() to occur twice. I read > the FAQ and it appears this is a common problem? Has anyone figured out > a workaround? Thanks. Not sure I understand the question, but maybe you're referring to the just-sent string appearing in the response? That would be the "echo" from the application, which is normal for interactive applications. If you're driving the application manually, each character you see in response to what you type is coming back from the application, not from your local terminal. When automating this, you just need to expect to see the same string (usually) just sent, usually with the end-of-line character(s) changed ("foo\r" is sent, "foo\n" or "foo\r\n" is seen in response). The echo might be considered a confirmation that the app has gotten the right command, or an indication of the state of the application. The command's response should immediately follow the echo. > my $exp = new Expect; > $exp->raw_pty(1); > $exp->spawn("randomApplication.pl"); > > while ($value != 3) { > my $value = $exp->expect($timeout, > [ qr/sender/], > [ qr/receiver/], > [ qr/whatever/] > ); > > if ($value == 1) { > $exp-send("Yes"); > } > elsif ($value == 2) { > $exp-send("No"); > } > } Or maybe you meant something else... I don't follow what the code snippet is intended to demonstrate/illustrate. Ken -- Ken Irving, fn...@ua... |
From: Chuck S. <Chu...@me...> - 2007-07-26 15:08:25
|
It appears that whenever I use send(), the next expect() will read the previous line again and thus causing the send() to occur twice. I read the FAQ and it appears this is a common problem? Has anyone figured out a workaround? Thanks. my $exp = new Expect; $exp->raw_pty(1); $exp->spawn("randomApplication.pl"); while ($value != 3) { my $value = $exp->expect($timeout, [ qr/sender/], [ qr/receiver/], [ qr/whatever/] ); if ($value == 1) { $exp-send("Yes"); } elsif ($value == 2) { $exp-send("No"); } } |
From: Bryan B. <br...@bu...> - 2007-07-18 14:31:28
|
> On 7/16/07, Bryan Bueter <br...@bu...> wrote: >> I persued Net::SSH2 over a year ago for just this purpose. You can read >> the thread I had with the author here: >> >> http://sourceforge.net/mailarchive/message.php?msg_id=200601192208.43932.dbrobins%40cpan.org >> >> Basically David Robins stated this: >> >> Ah, then there's the problem. Fileno tries to get a real Unix filehandle >> out >> of the object; since it isn't a real Unix file, you won't get one. >> >> I could not get it to work, and David seemed to think that it should not >> work. In that thread there is very simple code that I wrote and even >> that >> doesnt work. > > I think all that would be needed is that Net::SSH2::Channel returns > the fileno of the socket connection. Expect needs a real fileno to do > a select() on it, but everything else is done via the object. > > Ideally, Net::SSH2 should be rewritten as an I/O filter ala > PerlIO::gzip. Well, one may dream... :-) > >> However, all that aside, even without using Expect, Net::SSH2 was not >> thread safe. I sent emails regarding that as well, to no avail. At >> this >> point in time, I really think Expect on top of a spawned ssh command is >> the best way to do things (from a perl perspective). > > I browsed through the source and didn't notice anything obvious that > could hinder thread-usage. Can you remember what it was that was not > thread-safe? > > Yeah, let's stick to ssh for now, nothing wrong with that. But please, > people, remember to not use password-authentication... > > Best regards, Roland > If I remember correctly, when i tried threading with Net::SSH2 in the past (v0.06), it would connect to multiple sessions and then hang when reading from those channels simultaneously. However, now I cant even get the latest version (v0.10) to work in single threaded mode. So for the moment i'm not going to waste any more time on it. Thanks, Bryan Bueter http://sourceforge.net/projects/rover |
From: Roland G. <rgi...@cp...> - 2007-07-18 12:19:02
|
On 7/16/07, Bryan Bueter <br...@bu...> wrote: > I persued Net::SSH2 over a year ago for just this purpose. You can read > the thread I had with the author here: > > http://sourceforge.net/mailarchive/message.php?msg_id=200601192208.43932.dbrobins%40cpan.org > > Basically David Robins stated this: > > Ah, then there's the problem. Fileno tries to get a real Unix filehandle out > of the object; since it isn't a real Unix file, you won't get one. > > I could not get it to work, and David seemed to think that it should not > work. In that thread there is very simple code that I wrote and even that > doesnt work. I think all that would be needed is that Net::SSH2::Channel returns the fileno of the socket connection. Expect needs a real fileno to do a select() on it, but everything else is done via the object. Ideally, Net::SSH2 should be rewritten as an I/O filter ala PerlIO::gzip. Well, one may dream... :-) > However, all that aside, even without using Expect, Net::SSH2 was not > thread safe. I sent emails regarding that as well, to no avail. At this > point in time, I really think Expect on top of a spawned ssh command is > the best way to do things (from a perl perspective). I browsed through the source and didn't notice anything obvious that could hinder thread-usage. Can you remember what it was that was not thread-safe? Yeah, let's stick to ssh for now, nothing wrong with that. But please, people, remember to not use password-authentication... Best regards, Roland |
From: Austin S. <te...@of...> - 2007-07-16 17:08:54
|
On Mon, Jul 16, 2007 at 12:38:24PM +0200, Roland Giersig wrote: > Hmm, could be the wait delay in soft/hard_close which is trying to > send signals to the spawned process via "kill". Maybe that also > doesn't work in a thread (like fork()). Could you try closing the > Expect objects in the main thread? Maybe that gets rid of the delay... > soft_close (e.g.) will read from the process until it returns EOF, then wait on the process until it dies. This is typically considered responsible behavior because it reduces the possibility of leaving zombies around. My question would be "what is ssh doing instead of exiting?" Maybe truss/strace would answer that question. Austin |
From: Bryan B. <br...@bu...> - 2007-07-16 11:40:11
|
> Hmm, could be the wait delay in soft/hard_close which is trying to > send signals to the spawned process via "kill". Maybe that also > doesn't work in a thread (like fork()). Could you try closing the > Expect objects in the main thread? Maybe that gets rid of the delay... > > Seems a sensible rule to me: "Create and destroy Expect objects only > in the main thread." > Actually its the other way around. If i soft/hard close the object in the thread it takes a reasonable amount of time. If I soft/hard close it in the main thread it takes longer. The actual delay is in the join function, then closing the objects works normally. I re-wrote the last script to output the number of seconds elapsed and here is the output: Getting expect object for mythtv: 0 seconds Getting expect object for valhalla: 0 seconds Getting expect object for eldorado: 0 seconds Spawning thread: 1 seconds Spawning thread: 1 seconds Spawning thread: 1 seconds Joining thread 0 (mythtv): 1 seconds Completed joining thread 0 (mythtv): 16 seconds Closing expect object: 16 seconds Joining thread 1 (eldorado): 16 seconds Completed joining thread 1 (eldorado): 16 seconds Closing expect object: 16 seconds Joining thread 2 (valhalla): 16 seconds Completed joining thread 2 (valhalla): 16 seconds Closing expect object: 16 seconds You can see it takes about 15 seconds to join the first thread and then things progress normally. > > BTW, anybody tried to use Net::SSH2 instead of spawning ssh? Net::SSH2 > objects are tied filehandles, so they should be usable via > exp_init()... > > Cheers! > Roland > I persued Net::SSH2 over a year ago for just this purpose. You can read the thread I had with the author here: http://sourceforge.net/mailarchive/message.php?msg_id=200601192208.43932.dbrobins%40cpan.org Basically David Robins stated this: Ah, then there's the problem. Fileno tries to get a real Unix filehandle out of the object; since it isn't a real Unix file, you won't get one. I could not get it to work, and David seemed to think that it should not work. In that thread there is very simple code that I wrote and even that doesnt work. However, all that aside, even without using Expect, Net::SSH2 was not thread safe. I sent emails regarding that as well, to no avail. At this point in time, I really think Expect on top of a spawned ssh command is the best way to do things (from a perl perspective). Thanks Bryan Bueter http://sourceforge.net/projects/rover |
From: Roland G. <rgi...@cp...> - 2007-07-16 10:38:28
|
Hmm, could be the wait delay in soft/hard_close which is trying to send signals to the spawned process via "kill". Maybe that also doesn't work in a thread (like fork()). Could you try closing the Expect objects in the main thread? Maybe that gets rid of the delay... Seems a sensible rule to me: "Create and destroy Expect objects only in the main thread." BTW, anybody tried to use Net::SSH2 instead of spawning ssh? Net::SSH2 objects are tied filehandles, so they should be usable via exp_init()... Cheers! Roland On 7/16/07, Bryan Bueter <br...@bu...> wrote: > > Austin/Roland, > > > > Ok, there have been a few threads lately about threading so I thought i > > would re-visit the issue. I wrote a script that seems to work, but I > > would like your opinions on if it really should be working, and/or any > > snafu's i may run into if I continue doing it this way. > > > > Ok, responding to my own thread... I've been playing with this because > even though the login portion is single threaded, it still outperforms > forking and running in parallel. However, I think i ran into one bug that > I am consistently able to re-produce. > > My previous script works fine and is pretty quick to spawn and join the > threads. However, it seems that if I exit and soft_close()/hard_close() > the expect object after the thread is joined, it hangs for a couple of > seconds before joining the first thread. > > Here is the script that causes the join() delay. You can compare this to > my previous script to demonstrate what I'm talking about. > > --- start ---> > #!/usr/bin/perl -w > > use strict; > use threads; > > use Expect; > $Expect::Log_Stdout = 0; > > our $prompt = '[>#\$] $'; > my @hosts = ("mythtv", "valhalla", "eldorado" ); > my %hosts_exp; > > foreach my $host (@hosts) { > print "Getting expect object for $host\n"; > $hosts_exp{$host} = new Expect; > > $hosts_exp{$host}->log_file("$host.log"); > $hosts_exp{$host}->spawn("ssh -x $host"); > $hosts_exp{$host}->expect(5, '-re', $prompt); > } > > my $thread_id = 0; > my @thread_ids = (); > my @thread_hosts; > my @commands = ("uptime", "who", "who am i", "pwd"); > foreach my $host ( keys %hosts_exp ) { > $thread_ids[$thread_id] = threads->new("run_threaded", > $hosts_exp{$host}, $host, @commands); > $thread_hosts[$thread_id] = $host; > > $thread_id++; > } > > for (my $t=0; $t<$thread_id; $t++) { > print "Joining thread $t (". $thread_hosts[$t] .")\n"; > my $result = $thread_ids[$t]->join(); > print "Completed joining thread $t (". $thread_hosts[$t] .")\n"; > > if ($result) { > $hosts_exp{$thread_hosts[$t]}->send("exit;\n exit;\n exit;\n"); > $hosts_exp{$thread_hosts[$t]}->soft_close(); > } else { > print "Thread $t returned bad result\n"; > $hosts_exp{$thread_hosts[$t]}->hard_close(); > } > > } > > sub run_threaded { > my $exp = shift; > my $hostname = shift; > my @commands = @_; > > my $result = 0; > foreach my $command (@commands) { > print "Executing on $hostname: $command\n"; > $exp->send("$command \n"); > $result = $exp->expect(5, '-re', $prompt); > last if ! $result; > } > > return($result); > } > <--- end --- > > Thanks, please let me know what you think. > > > Bryan Bueter > http://sourceforge.net/projects/rover > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > _______________________________________________ > Expectperl-discuss mailing list > Exp...@li... > https://lists.sourceforge.net/lists/listinfo/expectperl-discuss > |
From: Bryan B. <br...@bu...> - 2007-07-15 22:29:49
|
> Austin/Roland, > > Ok, there have been a few threads lately about threading so I thought i > would re-visit the issue. I wrote a script that seems to work, but I > would like your opinions on if it really should be working, and/or any > snafu's i may run into if I continue doing it this way. > Ok, responding to my own thread... I've been playing with this because even though the login portion is single threaded, it still outperforms forking and running in parallel. However, I think i ran into one bug that I am consistently able to re-produce. My previous script works fine and is pretty quick to spawn and join the threads. However, it seems that if I exit and soft_close()/hard_close() the expect object after the thread is joined, it hangs for a couple of seconds before joining the first thread. Here is the script that causes the join() delay. You can compare this to my previous script to demonstrate what I'm talking about. --- start ---> #!/usr/bin/perl -w use strict; use threads; use Expect; $Expect::Log_Stdout = 0; our $prompt = '[>#\$] $'; my @hosts = ("mythtv", "valhalla", "eldorado" ); my %hosts_exp; foreach my $host (@hosts) { print "Getting expect object for $host\n"; $hosts_exp{$host} = new Expect; $hosts_exp{$host}->log_file("$host.log"); $hosts_exp{$host}->spawn("ssh -x $host"); $hosts_exp{$host}->expect(5, '-re', $prompt); } my $thread_id = 0; my @thread_ids = (); my @thread_hosts; my @commands = ("uptime", "who", "who am i", "pwd"); foreach my $host ( keys %hosts_exp ) { $thread_ids[$thread_id] = threads->new("run_threaded", $hosts_exp{$host}, $host, @commands); $thread_hosts[$thread_id] = $host; $thread_id++; } for (my $t=0; $t<$thread_id; $t++) { print "Joining thread $t (". $thread_hosts[$t] .")\n"; my $result = $thread_ids[$t]->join(); print "Completed joining thread $t (". $thread_hosts[$t] .")\n"; if ($result) { $hosts_exp{$thread_hosts[$t]}->send("exit;\n exit;\n exit;\n"); $hosts_exp{$thread_hosts[$t]}->soft_close(); } else { print "Thread $t returned bad result\n"; $hosts_exp{$thread_hosts[$t]}->hard_close(); } } sub run_threaded { my $exp = shift; my $hostname = shift; my @commands = @_; my $result = 0; foreach my $command (@commands) { print "Executing on $hostname: $command\n"; $exp->send("$command \n"); $result = $exp->expect(5, '-re', $prompt); last if ! $result; } return($result); } <--- end --- Thanks, please let me know what you think. Bryan Bueter http://sourceforge.net/projects/rover |
From: Bruno N. <bn...@gm...> - 2007-07-13 20:26:55
|
More info. I just tested that the extra \n after the ps command is only needed when the SSH server is an AIX system, the same thing doesn't hapen when the SSH server is a zLinux OS... :-( Why????!!!! Best regards, bruno |
From: Bruno N. <bn...@gm...> - 2007-07-13 20:08:24
|
Hello guys, I'm developing a perl module to login and execute commands via ssh using Expect. It's already on CPAN: http://search.cpan.org/~bnegrao/Net-SSH-Expect-0.08/lib/Net/SSH/Expect.pm<http://search.cpan.org/%7Ebnegrao/Net-SSH-Expect-0.08/lib/Net/SSH/Expect.pm> I'm facing some problems that i don't understand. Now i have a case where i need to send an extra "\n" character to make the prompt reapear after sending a some specific commands, not all. I did a simple script that exemplifies this behaviour. The script bellow is called ssh.pl. The usage is ssh.pl host username password It will login via ssh on host and execute the same four commands 100 times. The problem is shown in the line: $spawn->send("ps\n\n"); # NEEDS TWO \N\N HERE OR THE PROMPT DOESN'T RETURN!! WHY???? I simply don't understand why after sending a "ps\n" the prompt on the remote server doesn't appear, what makes it unavailable for the next command in the loop. But, for example, after sending a "who am i\n", one \n is enough to make the prompt reapear. Can you explain this phenomenon for me? Regards, bruno #!/usr/bin/perl # ssh.pl # ssh to a server and execute 4 commands in a loop, only to test Expect. # usage # ssh.pl host username password if( ! defined $ARGV[0] ) { print "Usage: ssh.pl <host> <username> <password> \n"; exit; } my ($host, $username, $password) = @ARGV; $username = $ENV{USER} if $username eq ""; #!/usr/bin/perl # ssh to a server and execute 4 commands in a loop, only to test Expect. # if( ! defined $ARGV[0] ) { print "Usage: ssh.pl <host> <username> <password> \n"; exit; } my ($host, $username, $password) = @ARGV; $username = $ENV{USER} if $username eq ""; use Expect; #use IO::Pty; my $spawn = new Expect; $spawn->raw_pty(1); $spawn->exp_internal(0); $spawn->spawn("ssh $username\@$host") or die $!; $spawn->log_stdout(0); my $ret = $spawn->expect(10, [ qr/\(yes\/no\)\?\s*$/ => sub { $spawn->send("yes\n"); exp_continue; } ], [ qr/assword:\s*$/ => sub { $spawn->send("$password\n") if defined $password; } ], [ qr/ogin:\s*$/ => sub { $spawn->send("$username\n"); exp_continue; } ], [ qr/REMOTE HOST IDEN/ => sub { print "FIX: .ssh/known_hosts\n"; exp_continue; } ], ); while ($spawn->expect(1, '-re', qr/[\s\S]+/)){ #swallow any output the server throws after loging in } my $PROMPT = 'SSH_PROMPT>> '; $spawn->send("PS1='$PROMPT'\n"); for (my $i = 100; $i > 0; $i--) { if ($spawn->expect(3, -re, qr/$PROMPT$/)) { print $spawn->before(); $spawn->send("df -m /\n"); } else { exit $i; } if ($spawn->expect(3, $PROMPT)) { print $spawn->before(); $spawn->send("ls -l /bin/ls\n"); } else { exit $i; } if ($spawn->expect(3, $PROMPT)) { print $spawn->before(); $spawn->send("who am i\n"); } else { exit $i; } if ($spawn->expect(3, $PROMPT)) { print $spawn->before(); $spawn->send("ps\n\n"); # NEEDS TWO \N\N HERE OR THE PROMPT DOESN'T RETURN!! WHY???? } else { exit $i; } print ("\n\n$i $i $i $i $i $i $i $i $i $i $i\n\n"); } exit; |
From: Ian M. <iw...@do...> - 2007-07-13 17:17:27
|
> >Hi All, > >I am using the Expect to give responses to the questions asked while >installation. Here is a problem I am facing. > >This is the question I am expecting to be asked and I am waiting for the >same question >Do you want to start Veritas Storage Foundation for DB2 processes now? >[y,n,q] (y) > >But, the problem is on some terminals the question appears as >Do you want to start Veritas Storage Foundation for DB2 processes now? >[y,n,q] (y) > >or even as >Do you want to start Veritas Storage Foundation for >DB2 processes now? [y,n,q] (y) > >How to handle such things? Please help. > >Thanks and Regards, >Prasad. Some problems like this are caused by the setup of the shell started using the spawn command. If the default line width is shorter than the ouput line from the program the line is wrapped on to the next line. What I often do is to wait for the first prompt and send a stty columns 200 so that output lines are not wrapped. Ian W Moor Department of Computing, iw...@do... Imperial College. 180 Queensgate London SW7 2AZ UK. |
From: Roland G. <rgi...@cp...> - 2007-07-13 16:16:54
|
>From the perlthrtut: "Thinking of mixing fork() and threads? Please lie down and wait until the feeling passes." ;-) Note that spawn() does a fork. So this can only work if you spawn() all SSH connections in the main thread and then pass the Expect objects to the threads for handling. Bryan Bueter has provided a working example for using Expect/SSH/threads on the mailing list. Hope this helps, Roland PS: Net::SSH2 looks promising because it's objects are tied filehandles and thus should work with Expect via exp_init(). But I haven't had the time to try that yet. Hopefully any day soon... On 7/11/07, schlum <jsc...@bo...> wrote: > > Hi, > > I spent few days on this one, but couldn't get it working... > > I am working under sunOS > bt1wxxxx#uname -a > SunOS bt1wxxxx 5.6 Generic_105181-23 sun4u sparc SUNW,Ultra-60 > > I can run the following script without any problem : > > #!/usr/bin/perl > use strict; > use Expect; > my $exp = Expect->new; > $exp->raw_pty(1); > my $test = $exp->spawn('/usr/local/bin/ssh', -l => 'my_user', 'my_host') or > die "Cannot spawn command: $!\n"; > my @test1 = $exp->expect(5,'-re','password:'); > $exp->clear_accum(); > my @test2 = $exp->send("my_pass\r\n"); > my @test3 = $exp->expect(15,'-re','my_host'); > my @test4 = $exp->send("sh privilege\r\n"); > > The last command is exectuted successfuly. > > But if I try this : > > #!/usr/bin/perl > use strict; > use Expect; > use threads; > use threads::shared; > use Thread::Queue::Any; > > my $thread = threads->new(\&threadJob,); > $thread->join; > > sub threadJob{ > my $exp = Expect->new; > $exp->raw_pty(1); > my $test = $exp->spawn('/usr/local/bin/ssh', -l => 'my_user', 'my_host') > or die "Cannot spawn command: $!\n"; > my @test1 = $exp->expect(5,'-re','password:'); > $exp->clear_accum(); > my @test2 = $exp->send("my_pass\r\n"); > my @test3 = $exp->expect(15,'-re','my_host'); > my @test4 = $exp->send("sh privilege\r\n");# On envoie le mdp > } > > I actually get connected, but Expect don't interact anymore with ssh after > the logging. Instead, I can access the box, I telneted from STDIN ... > > Does anybody knows why I'm getting this strange behavior ? > > Btw, when I close the conection, the script finishes to run peacefully. > > -- > View this message in context: http://www.nabble.com/Trouble-with-Expect-working-with-Threads-tf4062209.html#a11541250 > Sent from the Perl - Expectperl-Discuss mailing list archive at Nabble.com. > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > _______________________________________________ > Expectperl-discuss mailing list > Exp...@li... > https://lists.sourceforge.net/lists/listinfo/expectperl-discuss > |
From: Bryan B. <br...@bu...> - 2007-07-12 17:45:32
|
Austin/Roland, Ok, there have been a few threads lately about threading so I thought i would re-visit the issue. I wrote a script that seems to work, but I would like your opinions on if it really should be working, and/or any snafu's i may run into if I continue doing it this way. My script (which I will add to this e-mail) does the following steps in order: 1. Initialize and store 1 expect object for each host, spawning an SSH command 2. Get to a command prompt on each expect object, so we have some place to start 3. Start one thread for each host, sending a list of commands, expecting the prompt in between each command 4. Close the expect object and return, joining thread I know it works with at least 5 hosts because i keep separate logs for each expect session. I'm using Expect v1.20, IO::Tty v1.07, and i've tried this on two different hosts: SunOS 5.10 Generic_125101-09 i86pc Redhat Linux AS4 2.6.9-5.EL And finally, here is the script: --- start ---> #!/usr/bin/perl -w use strict; use threads; use Expect; $Expect::Log_Stdout = 0; our $prompt = '[>#\$] $'; my @hosts = ("ravager", "jupiter", "europa", "firebee", "invader"); my %hosts_exp; foreach my $host (@hosts) { print "Getting expect object for $host\n"; $hosts_exp{$host} = new Expect; $hosts_exp{$host}->log_file("$host.log"); $hosts_exp{$host}->spawn("ssh -x $host"); $hosts_exp{$host}->expect(5, '-re', $prompt); } my $thread_id = 0; my @thread_ids = (); my @commands = ("uptime", "who", "who am i", "pwd"); foreach my $host ( keys %hosts_exp ) { $thread_ids[$thread_id] = threads->new("run_threaded", $hosts_exp{$host}, $host, @commands); $thread_id++; } for (my $t=0; $t<$thread_id; $t++) { my $result = $thread_ids[$t]->join(); if ( ! $result ) { print "Thread $t returned bad result\n"; } } sub run_threaded { my $exp = shift; my $hostname = shift; my @commands = @_; my $result = 0; foreach my $command (@commands) { print "Executing on $hostname: $command\n"; $exp->send("$command \n"); $result = $exp->expect(5, '-re', $prompt); last if ! $result; } if ($result) { $exp->send("exit;\n exit;\n exit;\n"); $exp->soft_close(); } else { $exp->hard_close(); } return($result); } <--- end --- Thanks, Bryan Bueter http://sourceforge.net/projects/rover |
From: schlum <jsc...@bo...> - 2007-07-12 11:02:41
|
Matt Zagrabelny wrote: > > On Wed, 2007-07-11 at 11:56 -0700, Austin Schutz wrote: >> On Wed, Jul 11, 2007 at 10:50:32AM -0500, Matt Zagrabelny wrote: >> > [...] >> > >> > > Does anybody knows why I'm getting this strange behavior ? >> > >> > Check the archives. >> > >> > From [1] comes: >> > >> > >> >> > While Expect is supposed to be reasonably threadsafe, IO-Tty is *not*, >> > that's where the problems come from. If you want to automate telnet, >> > using Net::Telnet with Expect should be possible under threads. >> > << >> > >> > I have had issues getting expect to use a spawned Net::Telnet object as >> > well (which is "supposed to be" thread safe). After much gnashing of >> > teeth, i have given up on Expect and been using Net::Telnet alone; >> which >> > is disappointing, because Expect is much more powerful and elegant than >> > Net::Telnet, however many *many* hours were wasted trying to get them >> to >> > work together across a diverse population of Cisco gear. >> > >> >> Have you tried using exp_init on a Net::Telnet object? That doesn't >> use IO::Tty. > > Yes, and by in large it worked. However, there were some Cisco switches > that it did not work for. So... I emailed the list and a fellow gave me > some good advice and my problems were solved, so I thought. There were > still some anomalies that were not working correctly. So to recap: > > * Expect worked with everything, but no threads > > * Expect with Net::Telnet was threaded, but could not communicate to all > switches > > * Expect with Net::Telnet plus trick from mailing list was able to > communicate to almost all switches, but not all > > Hence... > > I now use Net::Telnet by itself. It is not as elegant as Expect, but the > thread speedup is *awesome*. > > -- > Matt Zagrabelny - mzagrabe@d.umn.edu - (218) 726 8844 > University of Minnesota Duluth > Information Technology Systems & Services > PGP key 1024D/84E22DA2 2005-11-07 > Fingerprint: 78F9 18B3 EF58 56F5 FC85 C5CA 53E7 887F 84E2 2DA2 > > He is not a fool who gives up what he cannot keep to gain what he cannot > lose. > -Jim Elliot > > Hi ! Thank you for your answers. Actually my need seems to be the same as you : I want to automatize some operations on routers/switch/... I have about 2500 boxes to manage => I need the multithreading in most cases. For me everything worked fine with expect/telnet/threaded, as for SNMP/threaded. But we are now desactivating the Telnet on the infrastructure, so I really need to find a remplacement to Telnet. Most Cisco equipments only support SSH V1, so the only way I found so far is to use Expect. You think there is no hope of getting Expect/SSH/threaded working ? What struck me (and let me some hope) is that the trouble appear with only one thread running... So far it's not a thread compatibily bug, no ? I haven't try yet to use exp_init, but I am not sure what FILEHANDLE I am suppose to feed it with. Is there a way to get a filehandle from a ssh conection in Perl ? Thank you very much for your help. Jerome -- View this message in context: http://www.nabble.com/Trouble-with-Expect-working-with-Threads-tf4062209.html#a11557709 Sent from the Perl - Expectperl-Discuss mailing list archive at Nabble.com. |
From: Prasad J. <pra...@sy...> - 2007-07-12 08:03:30
|
Hi All, I am using the Expect to give responses to the questions asked while installation. Here is a problem I am facing. This is the question I am expecting to be asked and I am waiting for the same question Do you want to start Veritas Storage Foundation for DB2 processes now? [y,n,q] (y) But, the problem is on some terminals the question appears as Do you want to start Veritas Storage Foundation for DB2 processes now? [y,n,q] (y) or even as Do you want to start Veritas Storage Foundation for DB2 processes now? [y,n,q] (y) How to handle such things? Please help. Thanks and Regards, Prasad. |