in reply to Net::SSH2 exec timeout

I tried using threads::shared but I couldn't seem to pass the reference to $ssh on to my thread.

Try it this way:

use threads; use Net::... my $ssh = ...; $ssh->scp_put($firmware[$antenna_type],'/tmp/fwupdate.bin'); async { print "Upgrading firmware, this will take about 3 minutes.\n"; my $chan = $ssh->channel(); $chan->exec("/sbin/fwupdate -m\n"); $chan->close; }->detach; ...

That should "work" and allow your main thread to continue. The thread Will hang around until the connection times out, but is that a problem?

Alternatively, could you detach the remote process into the background using &:

$ssh->scp_put($firmware[$antenna_type],'/tmp/fwupdate.bin'); print "Upgrading firmware, this will take about 3 minutes.\n"; my $chan = $ssh->channel(); $chan->exec( "/sbin/fwupdate -m &\n"); ### Note: & $chan->close;

Wouldn't that allow the connection to complete in a timely fashion?


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: Net::SSH2 exec timeout
by £okì (Scribe) on Sep 08, 2011 at 22:17 UTC
    I like your solution and am perfectly fine with it hanging until the timeout. . However, I still get the same error as I would with a normal threads in that $ssh is not correctly passed
    Thread 1 terminated abnormally: Can't call method "exec" on an undefined value at Configuration.pl
    If I pass the $ssh in as a ref:
    $ssh_ref = \$ssh; async { print "Upgrading firmware, this will take about 3 minutes. +\n"; my $chan = $$ssh_ref->channel(); $chan->exec("/sbin/fwupdate -m\n"); $chan->close; }->detach;

    I get this error. . I have NO idea what it means.
    perl: ath.c:193: _gcry_ath_mutex_lock: Assertion `*lock == ((ath_mutex_t) 0)' failed.
    Maybe I need to lock the var before I use it? Thoughts?

    The & does not seem to help either. .

      Why are you using a reference to the object instead of the object?


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
        Sorry for the confusion, I tried both.

        First using the object directly I get the error: Thread 1 terminated abnormally: Can't call method "exec" on an undefined value at Configuration.pl

        Then, if I try to pass it in as a reference as it looks like $ssh is coming in undefined, I get the error: perl: ath.c:193: _gcry_ath_mutex_lock: Assertion `*lock == ((ath_mutex_t) 0)' failed.