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