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