Guys you are really quick. I changed the grep statement as written by "hazylife". Added saving to file. About the answers from "kennethk" und "zentara" i need to expand my horizon the next days.
For testing it now with looping up to 20 times, i just added a sleep() (temporarely). The script will run after normal working hours of the server at night. So itīs not needed to be as quick as possible.
#!/usr/bin/perl -w
use Net::OpenSSH;
use File::Copy;
use Cwd;
use strict;
use warnings;
#connection:
my $ssh2convey99 = Net::OpenSSH->new('...');
$ssh2convey99->error and
die "Couldn't establish SSH connection: ". $ssh2convey99->error;
#get some data from remote host and fill array
my @ls = $ssh2convey99->capture(q/disptest | fgrep ' 900 ' | fgrep -
+v +1900 | grep -vE '0 ([RW]E|WAV?)' | awk '{print $3";", $6";" }'/);
$ssh2convey99->error and
die "remote ls command failed: " . $ssh2convey99->error;
# include variables and arrays for data preparation
my @split_array;
my @matrix_array;
my $mitzl = 0;
# prepare the data and store in the matrix
foreach my $el (@ls){
$mitzl ++;
@split_array = split(/;/,$el);
$matrix_array[$mitzl] = [@split_array];
}
#including variables, arrays, date and file for getting the needed dat
+a for all list elements
my @bt_matrix_array;
my $length_matrix_array = @matrix_array;
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localti
+me(time);
my $datum = sprintf "%04d%02d%02d" , $year+=1900 , $mon+=1 , $mday
+ ;
my $file = "$datum.csv";
#running thru the list and send command to remote host for every
+element.
#capture everey command return in new array
for(my $i = 2;$i <= 10;$i++) {
my @bt = $ssh2convey99->capture("bt $matrix_array[$i][0]");
#kick out the first two lines because i donīt want them
splice(@bt, 0, 2) ;
#write the actual array in a file. make the file if not existi
+ng. if already existing -> put the new data below the old one. add so
+me meta infos
open (DATEI, ">>$file") or die $!;
print DATEI "TE: $matrix_array[$i][0] Boxtype: $matrix_a
+rray[$i][1] \n @bt \n\n";
#make a break
sleep(1);
close (DATEI);
}
undef $ssh2convey99;
my $dir = cwd;
my $newdir = '//mnt/SharedFolder/';
move("$dir/$file", "$newdir/$file") or die "konnte Verzeichnis nicht o
+effnen: $!\n";
##http://perlmonks.org/index.pl?node=1080097