Crayola has asked for the wisdom of the Perl Monks concerning the following question:
#!/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 = ""; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Net::SSH::Perl problems
by zby (Vicar) on May 28, 2003 at 14:21 UTC | |
by Crayola (Initiate) on May 28, 2003 at 14:30 UTC | |
by jaa (Friar) on May 28, 2003 at 14:56 UTC | |
by Crayola (Initiate) on May 28, 2003 at 15:30 UTC | |
by Anonymous Monk on May 28, 2003 at 16:30 UTC | |
|
Re: Net::SSH::Perl problems
by KPeter0314 (Deacon) on May 28, 2003 at 14:52 UTC | |
by Crayola (Initiate) on May 28, 2003 at 15:33 UTC |