Paul M. Lambert
2008-Dec-12 15:08 UTC
[Net-ssh-users] Using Net::SSH::Multi with multiple passwords
I''m trying to figure out how to use Net::SSH::Multi with a series of hosts which may have different passwords. I''ve got it working in the case where my keys or a single password works, but I''d like to catch the Net::SSH::AuthenticationFailure exception and retry it with a new password. But I can''t seem to figure out how to change the options for the failed session before retrying it. Ideally, I''d like to keep an array of possible passwords, and when I catch a Net::SSH::AuthenticationFailure, retry it with the next password in the array. If I''ve tried all the passwords in the array, I''d prompt for another password. But only add it to the array if it worked. Does that make sense? Also, if anyone has any suggestions on how to easily duplicate "expect"-like behavior, I''m all ears. I only have to support simple password prompts (from sudo and some other site-specific commands), so I plan to append the output from each host to a buffer, then use a regexp to match the end of the buffer, and if it''s a recognized prompt, react accordingly. I''m worried about synchronization. I''m not sure how the threads in Net::SSH::Multi are implemented, but I don''t want to block all the connections waiting for input for a single prompt on one of them. At the same time, I would like to ensure that a request for a password from the user correctly blocks other sessions that request the same data, without prompting multiple times. Paul