Folks,

I am trying to use Net::SSH::Perl to do a non-interactive login to a system and run quite a few commands. The output of those commands would go to individual files. I cant seem to get it to log in noninteractivly. It fails on the ssh->login line below. I dont want to use a password or a passphrase. Any ideas what I am doing wrong? I am quite stumped.. I have ssh (openssh 3.5p1) currently setup so that from the normal command line, I can just type "ssh hostname" and access the system without typing a password or passphrase (I am well aware of the security implications). Its using rsa public keys I believe since I have a id_rsa and id_rsa.pub files in my home directory on the host I am running this from. I am running this as my normal userid not root.

Thanks,
Crayola
#!/usr/bin/perl # use Text::CSV; use Net::SSH::Perl; # Make sure this is the right filename for the command file! $CSVFILE = "collector-commands"; # Make sure this is the right filename for the host file! $HOSTFILE = "collector-hostlist"; # Read the csv file into an MD array my $csv = Text::CSV->new; open (CSVDATA, $CSVFILE) or die "Cant open commandfile\n"; while (<CSVDATA>) { next if /^#/; # skip comments next if /^\s*$/; # skip empty lines if ($csv->parse($_)) { my @field = $csv->fields; push @csv_array, [ @field ]; } } open (HOSTLIST, $HOSTFILE) or die "Cant open hostlist\n"; while ($host = <HOSTLIST>) { chomp $host; my $ssh = Net::SSH::Perl->new($host, debug => 1, protocol => 2); $ssh->login("myusername"); for $i ( 0 .. $#csv_array ) { $row = $csv_array[$i]; my($out, $err) = $ssh->cmd("$row->[0]"); # eventually we will pump all the output to a database # but for now.. it goes to individual files open (OUTFILE,">$host-$row->[1]"); print OUTFILE $out; close (OUTFILE); $out = ""; } }

In reply to Net::SSH::Perl problems by Crayola

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.