Subject: | Issue with <timeout> parameter in $ssh->exec() |
Hi,
I have been using v1.09 of Net::SSH::Expect and observed an issue with
the timeout feature in the exec() method.
At present specifying a timeout does not necessarily ensure that my
exec() call will return to the caller after the specified duration. This
is because the call from the method read_all() will only return when it
detects a <timeout> period of inactivity on the input stream (as also
mentioned in the documentation).
Which means, if I have launched a command CMD1, using $ssh->exec(CMD1,
n), and CMD1 prints to the STDOUT indefinitely, then my caller script
will also keep on waiting indefinitely for the exec() call to finish.
However, I was able to achieve the desired functionality, wherein there
is a provision to ensure that an exec() call returns to caller after a
specified interval, by making some changes to the code in Net/SSH/Expect.pm.
Following are the differences between my modified file and the original
file for v1.09:
-----------------
$ diff -b Expect.pm Expect.pm.original
419,420d418
< my $cmd_timeout = shift;
< my $start = time;
423,425d420
< if (defined $cmd_timeout) {
< last if ((time - $start) > $cmd_timeout);
< }
473d467
< my $cmd_timeout = shift;
475,477d468
< if (defined $cmd_timeout) {
< return $self->read_all($timeout, $cmd_timeout);
< }
-----------------
Hope there is a change to accommodate this issue in a future release.
If you need any other inputs, feel free to contact me.
Regards,
Anirban Ghosh