Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2024-04-23 19:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found