From personal experiance, here it what I can say. There are a few modules that make life easier in regards to ssh'ing around. Namely Net::SSH, and Net::SSH::Perl. The first is nice, but you *have* to use SSH Key exchange to authenticate against the remote host. This can lead to either security policy or administration nightmares. The second I have gotten to compile on FreeBSD, OpenBSD, and Linux as well as run cleanly without issues. I have had issues with it under Solaris 2.6->2.9. Net::SSH::Perl also has a huge prerequisite list of modules which kind of makes it not so nice for roll out in your enterprise network. Net::SSH::Perl has alot of whizbang functionality that just can't be beat for anything you need to do remotely including inline SCP through the SSH tunnel established.

Now aside from the modules you can use SSH the way you want to. My first guess would be that you are being prompted to provide a password to authenticate against the remote system. But with both system and backticks this should come to STDERR (Im pretty sure its not STDOUT), and read from STDIN. So if you are calling this script from another script you might be missing that prompt. Also the SSH process communicates directy with the tty assigned to you, not the normal handles which makes working with it tricky.

I had to resort to using IPC::Open2 in my attempts to control the spawned process. Ultimately I failed in my attempts to provide a password at run time due to, I think, the fact that I was passing a clear text password to the process, which I think should have been encrypted first, then passed.

So the way around this is again to use SSH Keys, but like I said before make sure that is ok from a security policy standpoint on your network. (Picture someone comprimising the host your code resides on, finding your script, and then making use of the SSH Key exchange mechanism to wander through the hosts in question, all without raising alarms).

One last suggestion would be to try running system("ssh -v $host date"); This will provide a bunch of usefull information and quite possibly could point to what is failing. I.e possible TCP wrappers issues, DNS lookups, etc..

HTH..

MMMMM... Chocolaty Perl Goodness.....

In reply to Re: simple iterate and run cmd script by l2kashe
in thread simple iterate and run cmd script by patris

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.