Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: sending hundreds of commandos on SSH connection

by JGmonk (Initiate)
on Mar 28, 2014 at 16:58 UTC ( [id://1080115]=note: print w/replies, xml ) Need Help??


in reply to sending hundreds of commandos on SSH connection

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

Replies are listed 'Best First'.
Re^2: sending hundreds of commandos on SSH connection
by hazylife (Monk) on Mar 28, 2014 at 17:09 UTC
    fgrep -v +1900
    That should probably be fgrep -v 1900
Re^2: sending hundreds of commandos on SSH connection
by JGmonk (Initiate) on Mar 28, 2014 at 17:04 UTC

    Appendix: I get this error on every executed statement from the remote host
    "tput: No value for $TERM and no -T specified"

    somebody knows what to add on the ssh connection to get rid of it?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1080115]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2024-04-23 19:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found