timeouts for Net::SSH::W32Perl
yishayjobs_at_hotmail.com
Date: 01/27/05
- Previous message: Brian McCauley: "Re: GD::Graph isn't numeric etc."
- Next in thread: yishayjobs_at_hotmail.com: "Re: timeouts for Net::SSH::W32Perl"
- Reply: yishayjobs_at_hotmail.com: "Re: timeouts for Net::SSH::W32Perl"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 27 Jan 2005 01:23:45 -0800
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
- Previous message: Brian McCauley: "Re: GD::Graph isn't numeric etc."
- Next in thread: yishayjobs_at_hotmail.com: "Re: timeouts for Net::SSH::W32Perl"
- Reply: yishayjobs_at_hotmail.com: "Re: timeouts for Net::SSH::W32Perl"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|