I'm trying to ssh to multiple nodes in parallel via threads and it seems to work just fine. Only problem is when a node doesn't support passwordless ssh things go south.

My solution is to simply wait awhile in a loop, and if the ssh fails kill the thread. I read previous notes about setting up a signal handler in the thread and I tried that and it seems to work just fine. The reason I know this is I have a 'print' in the signal handler and I do see the results. Only problem was when the script eventually exits, it reports:

Perl exited with active threads: 0 running and unjoined 1 finished and unjoined
and I'm not sure what to do. What I did do was write a pretty small script that starts the thread, gives it a few seconds to run, and if the ssh doesn't finish and set a flag, it kills the thread. Only thing is now my signal isn't even firing! So now this is turning into a 2-part question:
- why doesn't the signal fire in the thread and
- if it does fire, how do I get rid of the 'unjoined' message at the end?
#!/usr/bin/perl -w use threads; use threads::shared; my $sshDone:shared; $sshDone=0; my $th=threads->create('test'); $th->join(); sleep 3; if (!$sshDone) { $th->kill('KILL'); print "Kill signal sent\n"; } sleep 2; sub test { $SIG{'KILL'} = sub { print "KILL THREAD\n"; threads->exit(); }; `ssh foo\@poker date`; $sshDone=1; }
note - if I use a valid user/hostname the script runs just fine and exits cleanly.

what is happening now is I see the echo of the password prompt to the ssh and then nothing! If I remove the join, I see the 'kill signal sent' message but then it just hangs.

gotta be something simple but I'm just not seeing it.

-mark


In reply to yet another thread/signal question by markseger

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.