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: David Li <w.d...@gm...> - 2011-04-08 17:19:32
|
Hi, Experts, I am new to Expect. Is there an example that uses both Net::Telnet and Expect to interact with Cisco routers? Regards, David |
From: <Sco...@we...> - 2011-02-22 00:00:24
|
Expect.pm Experts, I have been having the following problem, and was wondering if someone could provide a fix or workaround. When using the interact() function on Solaris 5.10 and Perl 5.8.4, everything I type is echoed back to the terminal 3 times (or 2 times too many). The extra echoes occur after I press the Enter key. Example script, exptest.pl use Expect; if ($ARGV[0] eq "-d") { $Expect::Log_Stdout=1; $Expect::Debug=3; $Expect::Exp_Internal=1; } my $process = Expect->spawn("cat > /dev/null") || die ("couldn't spawn: $!"); $process->interact(); When run from Solaris with the text "test\n", followed by Ctrl-D, I get the following: prompt> exptest.pl test test test ^D The command does not end when I type Ctrl-D. However, when I run the same script on Linux, I get the result I expect: prompt> exptest.pl test prompt> When I run with debugging, I can see that Expect is reading from the terminal the full text of what I typed, 2 extra times, and all from the same call to read(). prompt> exptest.pl -d Spawned 'cat > /dev/null' spawn id(3) Pid: 22103 Tty: /dev/pts/23 Expect::spawn('Expect', 'cat > /dev/null') called at ./exptest.pl line 12 Initialized handle id(4).' Initialized handle id(5).' Read handles: Read handle: 'spawn id(3)' Listen Handles: 'handle id(5)'. Read handle: 'handle id(4)' Listen Handles: 'spawn id(3)'. Setting handle id(4) to tty mode '-g' Setting tty for handle id(4) to 'raw -echo'. Setting handle id(4) to tty mode 'raw -echo' Attempting interconnection interconnect: read 1 byte(s) from handle id(4). Printed 't' to spawn id(3) from handle id(4). interconnect: read 1 byte(s) from spawn id(3). Printed 't' to handle id(5) from spawn id(3). tinterconnect: read 1 byte(s) from handle id(4). Printed 'e' to spawn id(3) from handle id(4). interconnect: read 1 byte(s) from spawn id(3). Printed 'e' to handle id(5) from spawn id(3). einterconnect: read 1 byte(s) from handle id(4). Printed 's' to spawn id(3) from handle id(4). interconnect: read 1 byte(s) from spawn id(3). Printed 's' to handle id(5) from spawn id(3). sinterconnect: read 1 byte(s) from handle id(4). Printed 't' to spawn id(3) from handle id(4). interconnect: read 1 byte(s) from spawn id(3). Printed 't' to handle id(5) from spawn id(3). tinterconnect: read 1 byte(s) from handle id(4). Printed '\r' to spawn id(3) from handle id(4). interconnect: read 17 byte(s) from spawn id(3). Printed '\r\ntest\r\r\ntest\r\r\r\n' to handle id(5) from spawn id(3). test test interconnect: read 1 byte(s) from handle id(4). Printed '\004' to spawn id(3) from handle id(4). interconnect: read 4 byte(s) from spawn id(3). Printed '^D\b\b' to handle id(5) from spawn id(3). ^D When I run from Linux, I get what I expect: prompt> exptest.pl -d Spawned 'cat > /dev/null' spawn id(3) Pid: 9836 Tty: /dev/pts/10 at HOMEDIR/perl/lib/perl5/site_perl/5.8.8/Expect.pm line 181 Expect::spawn('Expect', 'cat > /dev/null') called at ./exptest.pl line 12 Initialized handle id(4).' Initialized handle id(5).' Read handles: Read handle: 'spawn id(3)' Listen Handles: 'handle id(5)'. Read handle: 'handle id(4)' Listen Handles: 'spawn id(3)'. Setting handle id(4) to tty mode '-g' Setting tty for handle id(4) to 'raw -echo'. Setting handle id(4) to tty mode 'raw -echo' Attempting interconnection interconnect: read 1 byte(s) from handle id(4). Printed 't' to spawn id(3) from handle id(4). interconnect: read 1 byte(s) from spawn id(3). Printed 't' to handle id(5) from spawn id(3). tinterconnect: read 1 byte(s) from handle id(4). Printed 'e' to spawn id(3) from handle id(4). interconnect: read 1 byte(s) from spawn id(3). Printed 'e' to handle id(5) from spawn id(3). einterconnect: read 1 byte(s) from handle id(4). Printed 's' to spawn id(3) from handle id(4). interconnect: read 1 byte(s) from spawn id(3). Printed 's' to handle id(5) from spawn id(3). sinterconnect: read 1 byte(s) from handle id(4). Printed 't' to spawn id(3) from handle id(4). interconnect: read 1 byte(s) from spawn id(3). Printed 't' to handle id(5) from spawn id(3). tinterconnect: read 1 byte(s) from handle id(4). Printed '\r' to spawn id(3) from handle id(4). interconnect: read 2 byte(s) from spawn id(3). Printed '\r\n' to handle id(5) from spawn id(3). interconnect: read 1 byte(s) from handle id(4). Printed '\004' to spawn id(3) from handle id(4). interconnect: read 0 byte(s) from spawn id(3). Got EOF reading spawn id(3) Setting handle id(4) to tty mode '191:1280:15:35387:5:15:3:28:127:21:4:0:1:17:19:26:0' Closing handle id(4). at HOMEDIR/perl/lib/perl5/site_perl/5.8.8/Expect.pm line 1431 Expect::hard_close('Expect=GLOB(0x199a7610)') called at HOMEDIR/perl/lib/perl5/site_perl/5.8.8/Expect.pm line 1621 Expect::DESTROY('Expect=GLOB(0x199a7610)') called at ./exptest.pl line 13 eval {...} called at ./exptest.pl line 13 Expect::interact('Expect=GLOB(0x19894060)') called at ./exptest.pl line 13 handle id(4) closed. Closing spawn id(3). at HOMEDIR/perl/lib/perl5/site_perl/5.8.8/Expect.pm line 1431 Expect::hard_close('Expect=GLOB(0x19894060)') called at HOMEDIR/perl/lib/perl5/site_perl/5.8.8/Expect.pm line 1621 Expect::DESTROY('Expect=GLOB(0x19894060)') called at ./exptest.pl line 0 eval {...} called at ./exptest.pl line 0 spawn id(3) closed. Pid 9836 of spawn id(3) terminated, Status: 0xFFFFFFFFFFFFFFFF Closing handle id(5). at HOMEDIR/perl/lib/perl5/site_perl/5.8.8/Expect.pm line 1431 Expect::hard_close('Expect=GLOB(0x1959fb20)') called at HOMEDIR/perl/lib/perl5/site_perl/5.8.8/Expect.pm line 1621 Expect::DESTROY('Expect=GLOB(0x1959fb20)') called at ./exptest.pl line 0 eval {...} called at ./exptest.pl line 0 handle id(5) closed. prompt> I can see that after the Enter key is pressed, on Solaris I get: interconnect: read 17 byte(s) from spawn id(3). Printed '\r\ntest\r\r\ntest\r\r\r\n' to handle id(5) from spawn id(3). >From Linux: interconnect: read 2 byte(s) from spawn id(3). Printed '\r\n' to handle id(5) from spawn id(3). Something seems to be storing the keys I press in some sort of buffer, and then when the Enter key is pressed, it sends the entire line back onto the terminal for Expect to read. On Linux it is sending only the \r\n sequence. Does anyone know of any way to prevent this? I want the Solaris script to have the same behavior I am seeing on Linux. That is, I want the keys I type to be echoed, but only once. Is there a way to do this? Thanks, Scott |
From: ncmudbug <jam...@em...> - 2011-02-07 15:44:45
|
Update: I never found out how to tell why it was timing out inexplicably, but I think I solved my problem by incorporating retry loops where the timeout problem shows itself. So far, it is more reliable. Thanks all who replied to me! Jim -- View this message in context: http://old.nabble.com/Debugging-timeouts-tp30790551p30864793.html Sent from the Perl - Expectperl-Discuss mailing list archive at Nabble.com. |
From: Shea C. <she...@gm...> - 2011-02-02 01:54:40
|
This setup is admittedly a bit odd and may or may not actually be an issue with ExpectPerl, but here it is: ExpectPerl script on host machine launches ssh to target machine and logs in - this works fine launches microcom on target machine - also works fine The problem comes when I try to issue a command to the target machine's modem through microcom, let's say the command is ATI ---- Sending 'ATI\r' to spawn id(3) Returning from expect successfully. Starting EXPECT pattern matching... spawn id(3): list of patterns: #1: -re `(?-xism:OK)' spawn id(3): Does `\r\n' match: pattern #1: -re `(?-xism:OK)'? No. Waiting for new data (10 seconds)... ATI spawn id(3): Does `\r\nATI\r\n' match: pattern #1: -re `(?-xism:OK)'? No. Waiting for new data (10 seconds)... TIMEOUT ---- As you can see, it never actually submits the command, it just reads the echos in the micocom. However, if I replace the send with an interact and by hand type ATI^M (by doing ctrl-v, ctrl-m) and hit enter, it works: ---- Calling hook CODE(0x8355f28)... IO::Stty not installed, cannot change mode at ./sshtest.pl line 52 IO::Stty not installed, cannot change mode at ./sshtest.pl line 52 ATI^M ATI [Block of text removed from post, but what was expected] OK ---- Now, I've tried every variation on send I can think of, but they just echo back ATI and some characters: ^V^M/r - spawn id(3): Does `\r\nATI^\b^M\r\n' ^V^M - spawn id(3): Does `\r\nATI^\b^M' ^M/r - spawn id(3): Does `\r\nATI\r\n\r\n' /r/n - spawn id(3): Does `\r\nATI\r\n\r\n' My problem is I don't know which consoles/terminals are escaping which parts of the ctrl characters. I'm especially confused with how ^V^M gets turned into ^\b^M At first I wondered if the problem was stdin/stdout going to the modem and stderr going to the screen, but since the whole thing's wrapped in an ssh session, that shouldn't be distinguishable from the host machine, right? Just noticed: the behavior I'm seeing appears to be consistent with doing "cat | minicom" on the target machine (ATI^M by means of ^V works here too). |
From: Salvador F. <sfa...@ya...> - 2011-02-01 17:17:43
|
----- Original Message ---- > From: ncmudbug <jam...@em...> > To: exp...@li... > Sent: Tue, February 1, 2011 1:01:48 AM > Subject: Re: [Expectperl-discuss] Debugging timeouts > > > Thanks, Roland. The ssh idea sounds intriguing. Maybe you can help me with > it. If the command fails, I would like to know why from stderr. In my > playing with it, I didn't get an error message. Is there a way around that? > Jim Jim, If you need to automate an SSH process, you should try first using some of the SSH modules available from CPAN, for instance Net::OpenSSH (I am its author ;-), Net::SSH2 (recommended in Windows environments) or Net::SSH::Expect (recommended if you need to talk to network equipment or anything not running an standard command shell). They would allow you to get return codes from the remote commands and capture its I/O streams with minimum hashle. For instance: use Net::OpenSSH '1.51_01'; use Net::OpenSSH::Constants 'OSSH_SLAVE_CMD_FAILED'; my $ssh = Net::OpenSSH->new($remotehost, timeout => 10, kill_ssh_on_timeout => 1); $ssh->error and die "Unable to connect to remote host: " . $ssh->error; $ssh->system(test => -d => "/media/tmp") or do { if ($ssh->error == OSSH_SLAVE_CMD_FAILED) { die "Remote command failed, rc=" . ($? << 8); } else { die "SSH failed: " . $ssh->error; } } |
From: ncmudbug <jam...@em...> - 2011-02-01 00:01:55
|
Thanks, Roland. The ssh idea sounds intriguing. Maybe you can help me with it. If the command fails, I would like to know why from stderr. In my playing with it, I didn't get an error message. Is there a way around that? Jim Roland Giersig wrote: > > Your flags look fine. The log shows that no further string is received > back from the sssh connection after the echo of the command is > received. Try increasing the timeout value to 10 just to be sure that > it isn't a freak delay effect. > > Otherwise I'd work around the problem by not using Expect at all. ssh > gives you the exit() value of a remote command just fine, so use > system("ssh remotehost test -d /media/tmp") instead. ;-) > > Hope this helps, > > Roland > > > 2011/1/31 ncmudbug <jam...@em...>: >> >> This is not related to pattern matching. &run_and_expect is a subroutine >> I >> use for any command that I only care about its success or failure, not >> its >> output. It works correctly. I'm wondering if there might be some option I >> need to set... >> >> I start the program with: >> $Expect::Debug=0; >> $Expect::Exp_Internal=1; >> $Expect::Log_Stdout=0; >> ... >> then I log into the remote host and I'm off to the races. >> >> It sometimes appears that it doesn't wait for the entire timeout period >> or >> that the host doesn't execute the command but the fact that it is in the >> history, though seems to contradict that. >> >> kboragouda wrote: >>> >>> Something related to pattern matching? >>> >>> ~ >>> kb >>> >>> On Sat, Jan 29, 2011 at 5:17 AM, ncmudbug <jam...@em...> >>> wrote: >>> >>>> >>>> This is my first post. I tried searching for "timeout" but as you can >>>> imagine, the output was pretty voluminous! However, I didn't see any >>>> other >>>> questions similar to mine in the first several pages. Knowing my luck, >>>> somebody asked just the question on the page beyond where I stopped >>>> looking. >>>> >-( If so, just send me the link to the answer. >>>> I am using Perl-Expect to perform unattended tasks on a remote Linux >>>> machine. I am getting some timeout error on simple things that have a >>>> generous timeout value for it. For example, $mountpt is set to >>>> '/media/tmp'. >>>> I have the following call: >>>> >>>> $exists = &conn::run_and_expect ( $ssh, 2, "[ -d $mountpt ]" ); >>>> >>>> The code for &run_and_expect follows: >>>> >>>> sub run_and_expect >>>> { >>>> my ( $conn, $timeout, $cmd ) = @_; >>>> >>>> my $command = "$cmd >/dev/null 2> /tmp/err && echo SUCCESS || echo >>>> FAIL\n"; >>>> my $success = 0; >>>> my $got_error = 0; >>>> my $got_prompt = 0; >>>> >>>> $conn->clear_accum ( ); >>>> print $conn $command; >>>> $conn->expect ( $timeout, [ "\nSUCCESS\r\n", sub { >>>> $success = 1; >>>> exp_continue; >>>> } ], >>>> [ "\nFAIL\r\n", sub { >>>> my $ssh = shift; >>>> $success = 0; >>>> print $ssh "/bin/cat >>>> /tmp/err\n"; >>>> $ssh->expect ( 5, >>>> [ '-re', >>>> '\n.*\r\n', >>>> sub { >>>> my >>>> $error >>>> = >>>> $ssh->match ( ); >>>> chomp >>>> $error; >>>> >>>> $got_error >>>> = >>>> 1; >>>> >>>> &log::append_log ( $log::NO_ECHO, "$cmd returned with:$error" ); >>>> >>>> exp_continue; >>>> } ], >>>> [ '-re', >>>> $prompt, >>>> sub { >>>> if ( ! >>>> $got_error ) { >>>> >>>> &log::append_log ( $log::NO_ECHO, "$cmd failed" ); >>>> >>>> &log::append_log ( $log::NO_ECHO, "no error message found" ); >>>> >>>> $got_prompt = 1; >>>> } >>>> } ] >>>> ); >>>> $success = 0; >>>> exp_continue; >>>> } ], >>>> [ '-re', $prompt, sub { >>>> $success = $success; >>>> $got_prompt = 1; >>>> } ], >>>> timeout=> sub { >>>> if ( ! $got_prompt ) { >>>> &log::append_log ( >>>> $log::NO_ECHO, "we timed out running $cmd" ); >>>> $success = 0; >>>> } >>>> } >>>> ); >>>> return $success; >>>> } >>>> >>>> I am getting TIMEOUT errors: >>>> >>>> spawn id(4): Does `[ -d /media/tmp ] >/dev/null 2> /tmp/err && echo >>>> SUCCESS >>>> || echo FAIL\r\n'^M >>>> match:^M >>>> pattern #1: -re `\nSUCCESS\r\n'? No.^M >>>> pattern #2: -re `\nFAIL\r\n'? No.^M >>>> pattern #3: -re `(?-xism:# $)'? No.^M >>>> ^M >>>> Waiting for new data (2 seconds)...^M >>>> TIMEOUT^M >>>> Calling timeout function CODE(0x8655adc)...^M >>>> Returning from expect with TIMEOUT or EOF^M >>>> Starting EXPECT pattern matching...^M >>>> >>>> The machine is very lightly loaded - in fact, I am the only user logged >>>> on. >>>> The command shows up in the history of the remote machine. When I run >>>> the >>>> command by hand, it comes back instantly regardless of whether the >>>> directory >>>> is there or not (obviously, just checking for the existence of a >>>> directory >>>> is a trivial task and two seconds should be much more time than is >>>> necessary >>>> for that). Incidentally, this problem happens with other commands that >>>> should have no problem finishing during the timeout period. It seems >>>> that >>>> it >>>> doesn't make any difference what the timeout value is that sometimes, >>>> the >>>> command will still timeout regardless. >>>> >>>> Is there some way I can debug what is causing this simple command to >>>> time >>>> out? Any help would be GREATLY appreciated =). >>>> -- >>>> View this message in context: >>>> http://old.nabble.com/Debugging-timeouts-tp30790551p30790551.html >>>> Sent from the Perl - Expectperl-Discuss mailing list archive at >>>> Nabble.com. >>>> >>>> >>>> >>>> ------------------------------------------------------------------------------ >>>> Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)! >>>> Finally, a world-class log management solution at an even better >>>> price-free! >>>> Download using promo code Free_Logger_4_Dev2Dev. Offer expires >>>> February 28th, so secure your free ArcSight Logger TODAY! >>>> http://p.sf.net/sfu/arcsight-sfd2d >>>> _______________________________________________ >>>> Expectperl-discuss mailing list >>>> Exp...@li... >>>> https://lists.sourceforge.net/lists/listinfo/expectperl-discuss >>>> >>> >>> ------------------------------------------------------------------------------ >>> Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)! >>> Finally, a world-class log management solution at an even better >>> price-free! >>> Download using promo code Free_Logger_4_Dev2Dev. Offer expires >>> February 28th, so secure your free ArcSight Logger TODAY! >>> http://p.sf.net/sfu/arcsight-sfd2d >>> _______________________________________________ >>> Expectperl-discuss mailing list >>> Exp...@li... >>> https://lists.sourceforge.net/lists/listinfo/expectperl-discuss >>> >>> >> >> -- >> View this message in context: >> http://old.nabble.com/Debugging-timeouts-tp30790551p30807546.html >> Sent from the Perl - Expectperl-Discuss mailing list archive at >> Nabble.com. >> >> >> ------------------------------------------------------------------------------ >> Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)! >> Finally, a world-class log management solution at an even better >> price-free! >> Download using promo code Free_Logger_4_Dev2Dev. Offer expires >> February 28th, so secure your free ArcSight Logger TODAY! >> http://p.sf.net/sfu/arcsight-sfd2d >> _______________________________________________ >> Expectperl-discuss mailing list >> Exp...@li... >> https://lists.sourceforge.net/lists/listinfo/expectperl-discuss >> > > ------------------------------------------------------------------------------ > Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)! > Finally, a world-class log management solution at an even better > price-free! > Download using promo code Free_Logger_4_Dev2Dev. Offer expires > February 28th, so secure your free ArcSight Logger TODAY! > http://p.sf.net/sfu/arcsight-sfd2d > _______________________________________________ > Expectperl-discuss mailing list > Exp...@li... > https://lists.sourceforge.net/lists/listinfo/expectperl-discuss > > -- View this message in context: http://old.nabble.com/Debugging-timeouts-tp30790551p30812142.html Sent from the Perl - Expectperl-Discuss mailing list archive at Nabble.com. |
From: Roland G. <rgi...@cp...> - 2011-01-31 15:43:38
|
Your flags look fine. The log shows that no further string is received back from the sssh connection after the echo of the command is received. Try increasing the timeout value to 10 just to be sure that it isn't a freak delay effect. Otherwise I'd work around the problem by not using Expect at all. ssh gives you the exit() value of a remote command just fine, so use system("ssh remotehost test -d /media/tmp") instead. ;-) Hope this helps, Roland 2011/1/31 ncmudbug <jam...@em...>: > > This is not related to pattern matching. &run_and_expect is a subroutine I > use for any command that I only care about its success or failure, not its > output. It works correctly. I'm wondering if there might be some option I > need to set... > > I start the program with: > $Expect::Debug=0; > $Expect::Exp_Internal=1; > $Expect::Log_Stdout=0; > ... > then I log into the remote host and I'm off to the races. > > It sometimes appears that it doesn't wait for the entire timeout period or > that the host doesn't execute the command but the fact that it is in the > history, though seems to contradict that. > > kboragouda wrote: >> >> Something related to pattern matching? >> >> ~ >> kb >> >> On Sat, Jan 29, 2011 at 5:17 AM, ncmudbug <jam...@em...> wrote: >> >>> >>> This is my first post. I tried searching for "timeout" but as you can >>> imagine, the output was pretty voluminous! However, I didn't see any >>> other >>> questions similar to mine in the first several pages. Knowing my luck, >>> somebody asked just the question on the page beyond where I stopped >>> looking. >>> >-( If so, just send me the link to the answer. >>> I am using Perl-Expect to perform unattended tasks on a remote Linux >>> machine. I am getting some timeout error on simple things that have a >>> generous timeout value for it. For example, $mountpt is set to >>> '/media/tmp'. >>> I have the following call: >>> >>> $exists = &conn::run_and_expect ( $ssh, 2, "[ -d $mountpt ]" ); >>> >>> The code for &run_and_expect follows: >>> >>> sub run_and_expect >>> { >>> my ( $conn, $timeout, $cmd ) = @_; >>> >>> my $command = "$cmd >/dev/null 2> /tmp/err && echo SUCCESS || echo >>> FAIL\n"; >>> my $success = 0; >>> my $got_error = 0; >>> my $got_prompt = 0; >>> >>> $conn->clear_accum ( ); >>> print $conn $command; >>> $conn->expect ( $timeout, [ "\nSUCCESS\r\n", sub { >>> $success = 1; >>> exp_continue; >>> } ], >>> [ "\nFAIL\r\n", sub { >>> my $ssh = shift; >>> $success = 0; >>> print $ssh "/bin/cat >>> /tmp/err\n"; >>> $ssh->expect ( 5, >>> [ '-re', >>> '\n.*\r\n', >>> sub { >>> my $error >>> = >>> $ssh->match ( ); >>> chomp >>> $error; >>> $got_error >>> = >>> 1; >>> >>> &log::append_log ( $log::NO_ECHO, "$cmd returned with:$error" ); >>> >>> exp_continue; >>> } ], >>> [ '-re', >>> $prompt, >>> sub { >>> if ( ! >>> $got_error ) { >>> >>> &log::append_log ( $log::NO_ECHO, "$cmd failed" ); >>> >>> &log::append_log ( $log::NO_ECHO, "no error message found" ); >>> >>> $got_prompt = 1; >>> } >>> } ] >>> ); >>> $success = 0; >>> exp_continue; >>> } ], >>> [ '-re', $prompt, sub { >>> $success = $success; >>> $got_prompt = 1; >>> } ], >>> timeout=> sub { >>> if ( ! $got_prompt ) { >>> &log::append_log ( >>> $log::NO_ECHO, "we timed out running $cmd" ); >>> $success = 0; >>> } >>> } >>> ); >>> return $success; >>> } >>> >>> I am getting TIMEOUT errors: >>> >>> spawn id(4): Does `[ -d /media/tmp ] >/dev/null 2> /tmp/err && echo >>> SUCCESS >>> || echo FAIL\r\n'^M >>> match:^M >>> pattern #1: -re `\nSUCCESS\r\n'? No.^M >>> pattern #2: -re `\nFAIL\r\n'? No.^M >>> pattern #3: -re `(?-xism:# $)'? No.^M >>> ^M >>> Waiting for new data (2 seconds)...^M >>> TIMEOUT^M >>> Calling timeout function CODE(0x8655adc)...^M >>> Returning from expect with TIMEOUT or EOF^M >>> Starting EXPECT pattern matching...^M >>> >>> The machine is very lightly loaded - in fact, I am the only user logged >>> on. >>> The command shows up in the history of the remote machine. When I run the >>> command by hand, it comes back instantly regardless of whether the >>> directory >>> is there or not (obviously, just checking for the existence of a >>> directory >>> is a trivial task and two seconds should be much more time than is >>> necessary >>> for that). Incidentally, this problem happens with other commands that >>> should have no problem finishing during the timeout period. It seems that >>> it >>> doesn't make any difference what the timeout value is that sometimes, the >>> command will still timeout regardless. >>> >>> Is there some way I can debug what is causing this simple command to time >>> out? Any help would be GREATLY appreciated =). >>> -- >>> View this message in context: >>> http://old.nabble.com/Debugging-timeouts-tp30790551p30790551.html >>> Sent from the Perl - Expectperl-Discuss mailing list archive at >>> Nabble.com. >>> >>> >>> >>> ------------------------------------------------------------------------------ >>> Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)! >>> Finally, a world-class log management solution at an even better >>> price-free! >>> Download using promo code Free_Logger_4_Dev2Dev. Offer expires >>> February 28th, so secure your free ArcSight Logger TODAY! >>> http://p.sf.net/sfu/arcsight-sfd2d >>> _______________________________________________ >>> Expectperl-discuss mailing list >>> Exp...@li... >>> https://lists.sourceforge.net/lists/listinfo/expectperl-discuss >>> >> >> ------------------------------------------------------------------------------ >> Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)! >> Finally, a world-class log management solution at an even better >> price-free! >> Download using promo code Free_Logger_4_Dev2Dev. Offer expires >> February 28th, so secure your free ArcSight Logger TODAY! >> http://p.sf.net/sfu/arcsight-sfd2d >> _______________________________________________ >> Expectperl-discuss mailing list >> Exp...@li... >> https://lists.sourceforge.net/lists/listinfo/expectperl-discuss >> >> > > -- > View this message in context: http://old.nabble.com/Debugging-timeouts-tp30790551p30807546.html > Sent from the Perl - Expectperl-Discuss mailing list archive at Nabble.com. > > > ------------------------------------------------------------------------------ > Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)! > Finally, a world-class log management solution at an even better price-free! > Download using promo code Free_Logger_4_Dev2Dev. Offer expires > February 28th, so secure your free ArcSight Logger TODAY! > http://p.sf.net/sfu/arcsight-sfd2d > _______________________________________________ > Expectperl-discuss mailing list > Exp...@li... > https://lists.sourceforge.net/lists/listinfo/expectperl-discuss > |
From: ncmudbug <jam...@em...> - 2011-01-31 15:24:19
|
This is not related to pattern matching. &run_and_expect is a subroutine I use for any command that I only care about its success or failure, not its output. It works correctly. I'm wondering if there might be some option I need to set... I start the program with: $Expect::Debug=0; $Expect::Exp_Internal=1; $Expect::Log_Stdout=0; ... then I log into the remote host and I'm off to the races. It sometimes appears that it doesn't wait for the entire timeout period or that the host doesn't execute the command but the fact that it is in the history, though seems to contradict that. kboragouda wrote: > > Something related to pattern matching? > > ~ > kb > > On Sat, Jan 29, 2011 at 5:17 AM, ncmudbug <jam...@em...> wrote: > >> >> This is my first post. I tried searching for "timeout" but as you can >> imagine, the output was pretty voluminous! However, I didn't see any >> other >> questions similar to mine in the first several pages. Knowing my luck, >> somebody asked just the question on the page beyond where I stopped >> looking. >> >-( If so, just send me the link to the answer. >> I am using Perl-Expect to perform unattended tasks on a remote Linux >> machine. I am getting some timeout error on simple things that have a >> generous timeout value for it. For example, $mountpt is set to >> '/media/tmp'. >> I have the following call: >> >> $exists = &conn::run_and_expect ( $ssh, 2, "[ -d $mountpt ]" ); >> >> The code for &run_and_expect follows: >> >> sub run_and_expect >> { >> my ( $conn, $timeout, $cmd ) = @_; >> >> my $command = "$cmd >/dev/null 2> /tmp/err && echo SUCCESS || echo >> FAIL\n"; >> my $success = 0; >> my $got_error = 0; >> my $got_prompt = 0; >> >> $conn->clear_accum ( ); >> print $conn $command; >> $conn->expect ( $timeout, [ "\nSUCCESS\r\n", sub { >> $success = 1; >> exp_continue; >> } ], >> [ "\nFAIL\r\n", sub { >> my $ssh = shift; >> $success = 0; >> print $ssh "/bin/cat >> /tmp/err\n"; >> $ssh->expect ( 5, >> [ '-re', >> '\n.*\r\n', >> sub { >> my $error >> = >> $ssh->match ( ); >> chomp >> $error; >> $got_error >> = >> 1; >> >> &log::append_log ( $log::NO_ECHO, "$cmd returned with:$error" ); >> >> exp_continue; >> } ], >> [ '-re', >> $prompt, >> sub { >> if ( ! >> $got_error ) { >> >> &log::append_log ( $log::NO_ECHO, "$cmd failed" ); >> >> &log::append_log ( $log::NO_ECHO, "no error message found" ); >> >> $got_prompt = 1; >> } >> } ] >> ); >> $success = 0; >> exp_continue; >> } ], >> [ '-re', $prompt, sub { >> $success = $success; >> $got_prompt = 1; >> } ], >> timeout=> sub { >> if ( ! $got_prompt ) { >> &log::append_log ( >> $log::NO_ECHO, "we timed out running $cmd" ); >> $success = 0; >> } >> } >> ); >> return $success; >> } >> >> I am getting TIMEOUT errors: >> >> spawn id(4): Does `[ -d /media/tmp ] >/dev/null 2> /tmp/err && echo >> SUCCESS >> || echo FAIL\r\n'^M >> match:^M >> pattern #1: -re `\nSUCCESS\r\n'? No.^M >> pattern #2: -re `\nFAIL\r\n'? No.^M >> pattern #3: -re `(?-xism:# $)'? No.^M >> ^M >> Waiting for new data (2 seconds)...^M >> TIMEOUT^M >> Calling timeout function CODE(0x8655adc)...^M >> Returning from expect with TIMEOUT or EOF^M >> Starting EXPECT pattern matching...^M >> >> The machine is very lightly loaded - in fact, I am the only user logged >> on. >> The command shows up in the history of the remote machine. When I run the >> command by hand, it comes back instantly regardless of whether the >> directory >> is there or not (obviously, just checking for the existence of a >> directory >> is a trivial task and two seconds should be much more time than is >> necessary >> for that). Incidentally, this problem happens with other commands that >> should have no problem finishing during the timeout period. It seems that >> it >> doesn't make any difference what the timeout value is that sometimes, the >> command will still timeout regardless. >> >> Is there some way I can debug what is causing this simple command to time >> out? Any help would be GREATLY appreciated =). >> -- >> View this message in context: >> http://old.nabble.com/Debugging-timeouts-tp30790551p30790551.html >> Sent from the Perl - Expectperl-Discuss mailing list archive at >> Nabble.com. >> >> >> >> ------------------------------------------------------------------------------ >> Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)! >> Finally, a world-class log management solution at an even better >> price-free! >> Download using promo code Free_Logger_4_Dev2Dev. Offer expires >> February 28th, so secure your free ArcSight Logger TODAY! >> http://p.sf.net/sfu/arcsight-sfd2d >> _______________________________________________ >> Expectperl-discuss mailing list >> Exp...@li... >> https://lists.sourceforge.net/lists/listinfo/expectperl-discuss >> > > ------------------------------------------------------------------------------ > Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)! > Finally, a world-class log management solution at an even better > price-free! > Download using promo code Free_Logger_4_Dev2Dev. Offer expires > February 28th, so secure your free ArcSight Logger TODAY! > http://p.sf.net/sfu/arcsight-sfd2d > _______________________________________________ > Expectperl-discuss mailing list > Exp...@li... > https://lists.sourceforge.net/lists/listinfo/expectperl-discuss > > -- View this message in context: http://old.nabble.com/Debugging-timeouts-tp30790551p30807546.html Sent from the Perl - Expectperl-Discuss mailing list archive at Nabble.com. |
From: kboragouda <app...@gm...> - 2011-01-30 16:37:15
|
Something related to pattern matching? ~ kb On Sat, Jan 29, 2011 at 5:17 AM, ncmudbug <jam...@em...> wrote: > > This is my first post. I tried searching for "timeout" but as you can > imagine, the output was pretty voluminous! However, I didn't see any other > questions similar to mine in the first several pages. Knowing my luck, > somebody asked just the question on the page beyond where I stopped > looking. > >-( If so, just send me the link to the answer. > I am using Perl-Expect to perform unattended tasks on a remote Linux > machine. I am getting some timeout error on simple things that have a > generous timeout value for it. For example, $mountpt is set to > '/media/tmp'. > I have the following call: > > $exists = &conn::run_and_expect ( $ssh, 2, "[ -d $mountpt ]" ); > > The code for &run_and_expect follows: > > sub run_and_expect > { > my ( $conn, $timeout, $cmd ) = @_; > > my $command = "$cmd >/dev/null 2> /tmp/err && echo SUCCESS || echo > FAIL\n"; > my $success = 0; > my $got_error = 0; > my $got_prompt = 0; > > $conn->clear_accum ( ); > print $conn $command; > $conn->expect ( $timeout, [ "\nSUCCESS\r\n", sub { > $success = 1; > exp_continue; > } ], > [ "\nFAIL\r\n", sub { > my $ssh = shift; > $success = 0; > print $ssh "/bin/cat > /tmp/err\n"; > $ssh->expect ( 5, > [ '-re', > '\n.*\r\n', > sub { > my $error = > $ssh->match ( ); > chomp > $error; > $got_error = > 1; > > &log::append_log ( $log::NO_ECHO, "$cmd returned with:$error" ); > > exp_continue; > } ], > [ '-re', > $prompt, > sub { > if ( ! > $got_error ) { > > &log::append_log ( $log::NO_ECHO, "$cmd failed" ); > > &log::append_log ( $log::NO_ECHO, "no error message found" ); > > $got_prompt = 1; > } > } ] > ); > $success = 0; > exp_continue; > } ], > [ '-re', $prompt, sub { > $success = $success; > $got_prompt = 1; > } ], > timeout=> sub { > if ( ! $got_prompt ) { > &log::append_log ( > $log::NO_ECHO, "we timed out running $cmd" ); > $success = 0; > } > } > ); > return $success; > } > > I am getting TIMEOUT errors: > > spawn id(4): Does `[ -d /media/tmp ] >/dev/null 2> /tmp/err && echo SUCCESS > || echo FAIL\r\n'^M > match:^M > pattern #1: -re `\nSUCCESS\r\n'? No.^M > pattern #2: -re `\nFAIL\r\n'? No.^M > pattern #3: -re `(?-xism:# $)'? No.^M > ^M > Waiting for new data (2 seconds)...^M > TIMEOUT^M > Calling timeout function CODE(0x8655adc)...^M > Returning from expect with TIMEOUT or EOF^M > Starting EXPECT pattern matching...^M > > The machine is very lightly loaded - in fact, I am the only user logged on. > The command shows up in the history of the remote machine. When I run the > command by hand, it comes back instantly regardless of whether the > directory > is there or not (obviously, just checking for the existence of a directory > is a trivial task and two seconds should be much more time than is > necessary > for that). Incidentally, this problem happens with other commands that > should have no problem finishing during the timeout period. It seems that > it > doesn't make any difference what the timeout value is that sometimes, the > command will still timeout regardless. > > Is there some way I can debug what is causing this simple command to time > out? Any help would be GREATLY appreciated =). > -- > View this message in context: > http://old.nabble.com/Debugging-timeouts-tp30790551p30790551.html > Sent from the Perl - Expectperl-Discuss mailing list archive at Nabble.com. > > > > ------------------------------------------------------------------------------ > Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)! > Finally, a world-class log management solution at an even better > price-free! > Download using promo code Free_Logger_4_Dev2Dev. Offer expires > February 28th, so secure your free ArcSight Logger TODAY! > http://p.sf.net/sfu/arcsight-sfd2d > _______________________________________________ > Expectperl-discuss mailing list > Exp...@li... > https://lists.sourceforge.net/lists/listinfo/expectperl-discuss > |
From: ncmudbug <jam...@em...> - 2011-01-28 23:47:50
|
This is my first post. I tried searching for "timeout" but as you can imagine, the output was pretty voluminous! However, I didn't see any other questions similar to mine in the first several pages. Knowing my luck, somebody asked just the question on the page beyond where I stopped looking. >-( If so, just send me the link to the answer. I am using Perl-Expect to perform unattended tasks on a remote Linux machine. I am getting some timeout error on simple things that have a generous timeout value for it. For example, $mountpt is set to '/media/tmp'. I have the following call: $exists = &conn::run_and_expect ( $ssh, 2, "[ -d $mountpt ]" ); The code for &run_and_expect follows: sub run_and_expect { my ( $conn, $timeout, $cmd ) = @_; my $command = "$cmd >/dev/null 2> /tmp/err && echo SUCCESS || echo FAIL\n"; my $success = 0; my $got_error = 0; my $got_prompt = 0; $conn->clear_accum ( ); print $conn $command; $conn->expect ( $timeout, [ "\nSUCCESS\r\n", sub { $success = 1; exp_continue; } ], [ "\nFAIL\r\n", sub { my $ssh = shift; $success = 0; print $ssh "/bin/cat /tmp/err\n"; $ssh->expect ( 5, [ '-re', '\n.*\r\n', sub { my $error = $ssh->match ( ); chomp $error; $got_error = 1; &log::append_log ( $log::NO_ECHO, "$cmd returned with:$error" ); exp_continue; } ], [ '-re', $prompt, sub { if ( ! $got_error ) { &log::append_log ( $log::NO_ECHO, "$cmd failed" ); &log::append_log ( $log::NO_ECHO, "no error message found" ); $got_prompt = 1; } } ] ); $success = 0; exp_continue; } ], [ '-re', $prompt, sub { $success = $success; $got_prompt = 1; } ], timeout=> sub { if ( ! $got_prompt ) { &log::append_log ( $log::NO_ECHO, "we timed out running $cmd" ); $success = 0; } } ); return $success; } I am getting TIMEOUT errors: spawn id(4): Does `[ -d /media/tmp ] >/dev/null 2> /tmp/err && echo SUCCESS || echo FAIL\r\n'^M match:^M pattern #1: -re `\nSUCCESS\r\n'? No.^M pattern #2: -re `\nFAIL\r\n'? No.^M pattern #3: -re `(?-xism:# $)'? No.^M ^M Waiting for new data (2 seconds)...^M TIMEOUT^M Calling timeout function CODE(0x8655adc)...^M Returning from expect with TIMEOUT or EOF^M Starting EXPECT pattern matching...^M The machine is very lightly loaded - in fact, I am the only user logged on. The command shows up in the history of the remote machine. When I run the command by hand, it comes back instantly regardless of whether the directory is there or not (obviously, just checking for the existence of a directory is a trivial task and two seconds should be much more time than is necessary for that). Incidentally, this problem happens with other commands that should have no problem finishing during the timeout period. It seems that it doesn't make any difference what the timeout value is that sometimes, the command will still timeout regardless. Is there some way I can debug what is causing this simple command to time out? Any help would be GREATLY appreciated =). -- View this message in context: http://old.nabble.com/Debugging-timeouts-tp30790551p30790551.html Sent from the Perl - Expectperl-Discuss mailing list archive at Nabble.com. |
From: Keith C. <kei...@ya...> - 2010-12-09 17:02:04
|
Here is my sub to login and change a password my $spawnCmd="ssh $connStr -n '/usr/bin/passwd'"; $exp->log_stdout(0); $exp->log_file("kac","w"); my $timeout=$self->{'timeOut'}; $exp->raw_pty(1); $exp->exp_internal(1); unless ( $exp->spawn("$spawnCmd") ) { return wantarray ? ("2","Unable to spawn command to check for login") : "2"; } $exp->expect($timeout,"assword:","PASSCODE:"); print "Match: " . $exp->match() . "\n"; $exp->send("$oldpass\r"); $exp->expect($timeout, "ld password:", exp_continue); $exp->send("$oldpass\r"); $exp->expect($timeout,"choice here:"); $exp->send("p\r"); $exp->expect($timeout,"ew password:"); $exp->send("$newpass\r"); $exp->expect($timeout,"Re-enter"); $exp->send("$newpass\r"); $exp->expect($timeout,"successfully"); $exp->log_stdout(0); my $timeout=$self->{'timeOut'}; my $matchString=$exp->match(); $exp->hard_close(); if ( $matchString eq "successfully" ) { return wantarray ? ("1","Password changed.") : "1"; } Here is the error I get: Enter Securid PASSCODE: Not a terminal stty: : Not a typewriter stty: : Not a typewriter stty: : Not a typewriter ^[[3g ^[H ^[H ^[H ^[H ^[H ^[H ^[H ^[H ^[HChanging password for <user_id_deleted> pam_chauthtok: System error Any help is appreciated. |
From: Apollo J <apo...@ms...> - 2010-12-08 08:58:49
|
Hi, I manage to do in an other way using the module Net::SSH::Expect and it works.( Thanks for your reply ) foreach (keys (%sys)) { my ($out,$err,$exit)=""; my $cmd=''; if ($sys{$_} =~ /linux/i) { $cmd='service snmpd start'; } else { $cmd='/sbin/init.d/SnmpMaster start'; } print "**** $_ ****\n"; $ssh = Net::SSH::Expect -> new ( host => $injc, user => $user, #exp_debug => 2, #exp_internal => 1, raw_pty => 1 ); $ssh->run_ssh() or die "SSH process couldn't start: $!"; $ssh->send("ssh -o StrictHostKeyChecking=no $_ $cmd"); $ssh->waitfor('snmpd :[ OK ]',2,'-ex') and print $ssh->match() and next ; $ssh->waitfor('password:\s*\z',$timeout) or die "prompt 'password' not found after $timeout secondS"; # THE LOOP I WANTED foreach(@passwd) { $ssh->send($_); if (!$ssh->waitfor('password:\s*\z',2)) { last;} } print $ssh->peek() ; } > Date: Tue, 7 Dec 2010 10:30:02 -0800 > From: rlp...@di... > To: apo...@ms... > CC: exp...@li... > Subject: Re: [Expectperl-discuss] Using conditions in expect > > On Tue, Dec 07, 2010 at 01:45:28PM +0100, Ismaël BALLO wrote: > > > > Hi, > > > > I'm new to Expect.pm, I've written a piece of code : I started > > with one that works but I want to add some complexity I want to > > use a loop in case the first password is not good : > > > > I'm connecting from a first machine (pivot) then ssh a second > > machine to do $cmd on a third machine > > > > Questions : > > > > 1/ Is it possible to use named sub inside expects ( I didn't see > > examples ..) ? > > Right near the top of the man page: > > # or multi-match on several spawned commands with callbacks, > # just like the Tcl version > $exp->expect($timeout, > [ qr/regex1/ => sub { my $exp = shift; > $exp->send("response\n"); > exp_continue; } ], > [ "regexp2" , \&callback, @cbparms ], > ); > > \&callback is a reference to a function. > > > 2/ What do I miss to make this piece of code works ? > > How is it failing? Can you turn on debug(2) and post the results? > What did the simple version that worked look like? > > Also, I'd suggest seperating out the subroutines, for readability. > > -Robin > > -- > http://singinst.org/ : Our last, best hope for a fantastic future. > Lojban (http://www.lojban.org/): The language in which "this parrot > is dead" is "ti poi spitaki cu morsi", but "this sentence is false" > is "na nei". My personal page: http://www.digitalkingdom.org/rlp/ |
From: Robin L. P. <rlp...@di...> - 2010-12-07 18:30:10
|
On Tue, Dec 07, 2010 at 01:45:28PM +0100, Ismaël BALLO wrote: > > Hi, > > I'm new to Expect.pm, I've written a piece of code : I started > with one that works but I want to add some complexity I want to > use a loop in case the first password is not good : > > I'm connecting from a first machine (pivot) then ssh a second > machine to do $cmd on a third machine > > Questions : > > 1/ Is it possible to use named sub inside expects ( I didn't see > examples ..) ? Right near the top of the man page: # or multi-match on several spawned commands with callbacks, # just like the Tcl version $exp->expect($timeout, [ qr/regex1/ => sub { my $exp = shift; $exp->send("response\n"); exp_continue; } ], [ "regexp2" , \&callback, @cbparms ], ); \&callback is a reference to a function. > 2/ What do I miss to make this piece of code works ? How is it failing? Can you turn on debug(2) and post the results? What did the simple version that worked look like? Also, I'd suggest seperating out the subroutines, for readability. -Robin -- http://singinst.org/ : Our last, best hope for a fantastic future. Lojban (http://www.lojban.org/): The language in which "this parrot is dead" is "ti poi spitaki cu morsi", but "this sentence is false" is "na nei". My personal page: http://www.digitalkingdom.org/rlp/ |
From: Ismaël B. <apo...@ms...> - 2010-12-07 12:45:34
|
Hi, I'm new to Expect.pm, I've written a piece of code : I started with one that works but I want to add some complexity I want to use a loop in case the first password is not good : I'm connecting from a first machine (pivot) then ssh a second machine to do $cmd on a third machine Questions : 1/ Is it possible to use named sub inside expects ( I didn't see examples ..) ? 2/ What do I miss to make this piece of code works ? Here it is : // This login works ( I no need password) $ssh = Net::SSH::Perl -> new ( host => $host, user => $user, debug => 0, protocol => '2', port => 22, privileged => 0 ); $ssh->login($user); my $exp=new Expect; $exp->raw_pty(1); my $res="ssh $_ $cmd"; $exp->spawn($res) or print UNREACH "Cannot spawn $res : $! \n"; $exp->expect($timeout, [ qr/continue connecting .yes.no./ => sub _yes { $exp = shift; $exp->send("yes\n"); exp_continue; } ], [ qr/password:/ => sub _passwd{ $exp = shift; #$exp->send("master\n"); ## Comment : --> This is where I want to use other passwords until it works. I know I've got 3 max attempts but it suffices me foreach $passwd (@passwd) { print($passwd); $exp->send("$passwd\n"); $exp->expect($timeout, [ qr/password:/ => _password(); ] ) } exp_continue; } ], [ timeout => sub { print UNREACH "$host : Timeout \n"; } ] ); $exp->soft_close(); |
From: Madhav k. <mad...@ho...> - 2010-11-16 00:31:09
|
http://goo.gl/YEW11 |
From: Freddy C. <fre...@gm...> - 2010-10-12 14:52:56
|
Hi, I am trying to clear the contents of the accumulator and then execute the command and then capture the contents of the command via the expect log file. I am getting the output of the previous accumalator contents even after clearing them Code. $expect_handle->send("1st Command to be executed"); $expect_handle->clear_accum(); $expect_handle->log_file(undef); $expect_handle->log_file("expect_output_file","w"); $expect_handle->send("2nd Command to be executed"); $expect_handle->expect(undef,"prompt"); $output = `cat expect_output_file`; $output contains the output of the previous command ( e.g 1st command ) instead of the output of the 2nd command . I need $output to contain only the output of the 2nd command. Regards, Freddy |
From: Madhav k. <mad...@ho...> - 2010-10-10 01:03:51
|
http://qurl.com/9rz7b |
From: Robin L. P. <rlp...@di...> - 2010-09-23 17:52:56
|
On Thu, Sep 23, 2010 at 01:14:04PM +0530, saravana kumar wrote: > Resending it again.... > > --Saravana > > ---------- Forwarded message ---------- > From: saravana kumar <sar...@gm...> > Date: Wed, Sep 22, 2010 at 5:43 PM > Subject: Get the output from expect > To: exp...@li... > > > Hello All, > > I want to get the output from expect. > I tried with $exp->before(), $exp->after() and $exp->match(), but nothing > worked for me. > > Please find the script below: > > use strict; > use warnings; > use Expect; > my $output; > my $timeout = 200; > my $command = 'telnet pvham3-c.ind.hp.com'; > my $user='Admin'; > #my $host='192.168.47.11'; > my $password = 'Admin'; > my $exp = Expect->spawn($command) > or die "Cannot spawn $command: $!\n"; > $exp->expect($timeout, [ qr{MP login: } , sub {$exp->send("$user\n")} ]); > $exp->expect($timeout, [ qr{MP password: }, sub {$exp->send("$password\n")} > ]); > $exp->expect($timeout, [ qr{MP> }, sub {$exp->send("CO\r"); > $exp->send("\cEcf"); $exp->send("\r"); $exp->send("map -r\r")} ]); > $exp->expect($timeout, [ qr{fs*}, sub {$exp->send("cls\r"); $exp->send("map > -r\r")} ]); > #$exp->expect($timeout, [ qr{\$ } , sub {$exp->send("ls\n")} ]); > #$exp->expect($timeout, [ qr{fs*} , sub {print "got the output: '". > $exp->before(). $exp->after(). $exp->match() . "'\n"} ]); > $output=$exp->before() . $exp->after(). $exp->match(); > $exp->soft_close(); > print "The output is ********* $output\n"; > > >From the above script, i would want to capture the output from > "$exp->send("map -r\r")". >From "man expect 3pm": I just want to read the output of a process without expect()ing anything. How can I do this? [ Are you sure you need Expect for this? How about qx() or open("prog|")? ] By using expect without any patterns to match. $process->expect(undef); # Forever until EOF $process->expect($timeout); # For a few seconds $process->expect(0); # Is there anything ready on the handle now? Ok, so now how do I get what was read on the handle? $read = $process->before(); -Robin -- http://singinst.org/ : Our last, best hope for a fantastic future. Lojban (http://www.lojban.org/): The language in which "this parrot is dead" is "ti poi spitaki cu morsi", but "this sentence is false" is "na nei". My personal page: http://www.digitalkingdom.org/rlp/ |
From: saravana k. <sar...@gm...> - 2010-09-23 07:44:11
|
Resending it again.... --Saravana ---------- Forwarded message ---------- From: saravana kumar <sar...@gm...> Date: Wed, Sep 22, 2010 at 5:43 PM Subject: Get the output from expect To: exp...@li... Hello All, I want to get the output from expect. I tried with $exp->before(), $exp->after() and $exp->match(), but nothing worked for me. Please find the script below: use strict; use warnings; use Expect; my $output; my $timeout = 200; my $command = 'telnet pvham3-c.ind.hp.com'; my $user='Admin'; #my $host='192.168.47.11'; my $password = 'Admin'; my $exp = Expect->spawn($command) or die "Cannot spawn $command: $!\n"; $exp->expect($timeout, [ qr{MP login: } , sub {$exp->send("$user\n")} ]); $exp->expect($timeout, [ qr{MP password: }, sub {$exp->send("$password\n")} ]); $exp->expect($timeout, [ qr{MP> }, sub {$exp->send("CO\r"); $exp->send("\cEcf"); $exp->send("\r"); $exp->send("map -r\r")} ]); $exp->expect($timeout, [ qr{fs*}, sub {$exp->send("cls\r"); $exp->send("map -r\r")} ]); #$exp->expect($timeout, [ qr{\$ } , sub {$exp->send("ls\n")} ]); #$exp->expect($timeout, [ qr{fs*} , sub {print "got the output: '". $exp->before(). $exp->after(). $exp->match() . "'\n"} ]); $output=$exp->before() . $exp->after(). $exp->match(); $exp->soft_close(); print "The output is ********* $output\n"; >From the above script, i would want to capture the output from "$exp->send("map -r\r")". Appreciate help in advance. --Saravana |
From: saravana k. <sar...@gm...> - 2010-09-22 12:13:30
|
Hello All, I want to get the output from expect. I tried with $exp->before(), $exp->after() and $exp->match(), but nothing worked for me. Please find the script below: use strict; use warnings; use Expect; my $output; my $timeout = 200; my $command = 'telnet pvham3-c.ind.hp.com'; my $user='Admin'; #my $host='192.168.47.11'; my $password = 'Admin'; my $exp = Expect->spawn($command) or die "Cannot spawn $command: $!\n"; $exp->expect($timeout, [ qr{MP login: } , sub {$exp->send("$user\n")} ]); $exp->expect($timeout, [ qr{MP password: }, sub {$exp->send("$password\n")} ]); $exp->expect($timeout, [ qr{MP> }, sub {$exp->send("CO\r"); $exp->send("\cEcf"); $exp->send("\r"); $exp->send("map -r\r")} ]); $exp->expect($timeout, [ qr{fs*}, sub {$exp->send("cls\r"); $exp->send("map -r\r")} ]); #$exp->expect($timeout, [ qr{\$ } , sub {$exp->send("ls\n")} ]); #$exp->expect($timeout, [ qr{fs*} , sub {print "got the output: '". $exp->before(). $exp->after(). $exp->match() . "'\n"} ]); $output=$exp->before() . $exp->after(). $exp->match(); $exp->soft_close(); print "The output is ********* $output\n"; >From the above script, i would want to capture the output from "$exp->send("map -r\r")". Appreciate help in advance. --Saravana |
From: Matt Z. <mzagrabe@d.umn.edu> - 2010-09-16 14:36:33
|
On Thu, Sep 16, 2010 at 12:47 AM, Rajan Vijayaraghavan <raj...@gm...> wrote: > I tried $expect_obj->before() but it does not return the entire output. > > On Wed, Sep 15, 2010 at 11:07 PM, Satish Pothuri <sat...@gm...> > wrote: >> >> >> you can use expect before() function to get the command output. It >> actually captures the date from last expect string to current expect string. >> variable = $exp_obj->before() >> >> On Wed, Sep 15, 2010 at 11:31 PM, Rajan Vijayaraghavan >> <raj...@gm...> wrote: >>> >>> All, >>> I am using Perl with Expect for automating wpa_cli for wps. >>> I have a general question. For example if a command has been sent to >>> to either a remote machine or a spawned process, how to read the >>> entire output of the command executed. How does expect store so >>> that I can parse and use it for later purpose? Note, this is from memory: >From Expect.pm: $object->log_file("filename" | $filehandle | \&coderef | undef) my $expect_io; $object->log_file(sub { $expect_io .= $_; }); #Do stuff with Expect #Do stuff with $expect_io; HTH -matt |
From: Rajan V. <raj...@gm...> - 2010-09-16 05:47:32
|
I tried $expect_obj->before() but it does not return the entire output. On Wed, Sep 15, 2010 at 11:07 PM, Satish Pothuri <sat...@gm...>wrote: > > you can use expect before() function to get the command output. It actually > captures the date from last expect string to current expect string. > variable = $exp_obj->before() > > On Wed, Sep 15, 2010 at 11:31 PM, Rajan Vijayaraghavan < > raj...@gm...> wrote: > >> All, >> I am using Perl with Expect for automating wpa_cli for wps. >> I have a general question. For example if a command has been sent to >> to either a remote machine or a spawned process, how to read the >> entire output of the command executed. How does expect store so >> that I can parse and use it for later purpose? >> >> >> For example, if I telnet to a remote machine and read a file (cat >> <filename>) >> using expect. How can I store the entire cat output in a variable and use >> it >> for later parsing? Any pointer would be helpful. >> >> Thank you. >> >> -- >> Regards, >> Rajan Vijayaraghavan >> >> >> >> ------------------------------------------------------------------------------ >> Start uncovering the many advantages of virtual appliances >> and start using them to simplify application deployment and >> accelerate your shift to cloud computing. >> http://p.sf.net/sfu/novell-sfdev2dev >> _______________________________________________ >> Expectperl-discuss mailing list >> Exp...@li... >> https://lists.sourceforge.net/lists/listinfo/expectperl-discuss >> >> > -- Regards, Rajan Vijayaraghavan Mobile: +91 9880763421 |
From: Satish P. <sat...@gm...> - 2010-09-15 17:37:25
|
you can use expect before() function to get the command output. It actually captures the date from last expect string to current expect string. variable = $exp_obj->before() On Wed, Sep 15, 2010 at 11:31 PM, Rajan Vijayaraghavan < raj...@gm...> wrote: > All, > I am using Perl with Expect for automating wpa_cli for wps. > I have a general question. For example if a command has been sent to > to either a remote machine or a spawned process, how to read the > entire output of the command executed. How does expect store so > that I can parse and use it for later purpose? > > > For example, if I telnet to a remote machine and read a file (cat > <filename>) > using expect. How can I store the entire cat output in a variable and use > it > for later parsing? Any pointer would be helpful. > > Thank you. > > -- > Regards, > Rajan Vijayaraghavan > > > > ------------------------------------------------------------------------------ > Start uncovering the many advantages of virtual appliances > and start using them to simplify application deployment and > accelerate your shift to cloud computing. > http://p.sf.net/sfu/novell-sfdev2dev > _______________________________________________ > Expectperl-discuss mailing list > Exp...@li... > https://lists.sourceforge.net/lists/listinfo/expectperl-discuss > > |
From: Rajan V. <raj...@gm...> - 2010-09-15 15:32:02
|
All, I am using Perl with Expect for automating wpa_cli for wps. I have a general question. For example if a command has been sent to to either a remote machine or a spawned process, how to read the entire output of the command executed. How does expect store so that I can parse and use it for later purpose? For example, if I telnet to a remote machine and read a file (cat <filename>) using expect. How can I store the entire cat output in a variable and use it for later parsing? Any pointer would be helpful. Thank you. -- Regards, Rajan Vijayaraghavan |
From: Bryan B. <br...@bu...> - 2010-08-20 01:32:35
|
> I am experienced with Expect although I haven't used it for a few years > and > am an advanced-novice with Perl. I am looking for some examples of using > the Expect module with Net::Telnet as i am unable to glean inough > information from the perldoc Expect. If someone could spare a sample > script > or examples I would be much appreciative. > > Thank You > Here is my code: -- snip --> $t = new Net::Telnet (Timeout => $login_timeout, Prompt => "/". $user_prompt ."/", Input_log => $logs_dir ."/". $hostname .".log", Errmode => "return", ); if ( !$t->open($hostname) ) { die $t->errmsg(); } if ( !$t->login($username, $password) ) { die $t->errmsg(); } $exp = Expect->exp_init($t); <-- snip -- Then expect as normal. Also, it has been my experience that this is thread safe. Hope that helps. Bryan Bueter http://sourceforge.net/projects/rover/ |