|
Posted by yishayjobs on January 27, 2005, 2:23 am
Please log in for more thread options
To anyone interested,
I've been trying to find an effective way for dealing with
Net::SSH::W32Perl command timeouts. The 'timeout' issue can be defined
thus: "How can I make sure my perl script does not hang after sending a
remote ssh command?". For example:
my ($out, $err, $exit) = $ssh->cmd("./startSomeScript.sh");
# this should be executed next unless ssh cmd never returns
I've come up with 3 approaches, none of which are flawless.
1) use perl's alarm signal implementation (e.g.
alarm $timeout;
# some code
my ($out, $err, $exit) = $ssh->cmd("./startSomeScript.sh");
# some code
alarm 0;
# now carry on
The results for this have not been consistent. Depending on $timeout
command sometimes returns and sometimes doesn't. I'm not clear on
whether alarm mechanism is considered stable on windows (I'm using
ActiveState's 5.8.4 on XP and 2K). So I haven't investigated this much
further (hence the annoying '# some code' in example).
2) run remote process in background (e.g.
my ($out, $err, $exit) = $ssh->cmd("./startSomeScript.sh &");
# now carry on
In theory ssh cmd should return immediately, in practice there are
several conditions. One condition seems to be that file descriptors
opened by cmd are closed. This is not always easy to insure.
3) use perl's fork() implementation for windows (e.g.
unless (my $pid = fork() ) {
# make sure process process is stuck for consistent behavior
while (1) {}
} else {
my ($out, $err, $exit) = $ssh->cmd("./startSomeScript.sh");
my $time1 = time();
while (time() - $time1 < $timeout)
{
sleep 1;
}
kill $pid;
}
# $ssh needs to be given a new instance otherwise behavior is
unexpected
$ssh = Net::SSH::W32Perl->new('host');
$ssh->login('user', 'passwd');
# resume control here
This has proved the most effective approach so far. Unfortunately the
script hangs after being repeated for long enough and we suspect this
has to do with fork() overuse, although we may be wrong.
So in essence what I'm looking for is a differnet approach for ssh
timeouts which is not likely to have malicious side effects. We're
using this for an automated testing framework, so I'd like to be able
to repeat these commands for a day or more without having to worry
about unexpected hangs.
Any help would be much appreciated,
Yishay
|
|
Posted by yishayjobs on January 27, 2005, 8:11 am
Please log in for more thread options
Sorry - my mistake. Instead of
====================
unless (my $pid = fork() ) {
# make sure process process is stuck for consistent behavior
while (1) {}
} else {
my ($out, $err, $exit) = $ssh->cmd("./startSomeScript.sh");
my $time1 = time();
while (time() - $time1 < $timeout)
{
sleep 1;
}
kill $pid;
}
============
should be
============
unless (my $pid = fork() ) {
($out, $err, $exit) = $ssh->cmd("./startSomeScript.sh");
# make sure process is stuck for consistent behavior
while (1) {}
} else {
my $time1 = time();
while (time() - $time1 < $timeout)
{
sleep 1;
}
kill $pid;
}
|
| Similar Threads | Posted | | LWP, timeouts and error handling | September 5, 2004, 3:31 am |
| set_tty error from NET::SSH::W32PERL | August 24, 2004, 7:52 am |
| starting a background process via Net::SSH::W32Perl | September 7, 2004, 10:41 am |
| Net::SSH::W32Perl Script hanging when trying to return data | March 10, 2005, 1:14 pm |
| Net::SSH::W32Perl Script hanging when trying to return data | March 10, 2005, 1:30 pm |
| Net::SFTP / Net::SSH::W32Perl strange debug messages? | August 13, 2006, 11:06 am |
|