#!/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 () { 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 = ) { 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 = ""; } }