JGmonk has asked for the wisdom of the Perl Monks concerning the following question:
Hi All,
I am connecting to a remote host and excute commandos on the remote shell. First it gives me back a list of data what i am splitting up in arrays. Now i want to send a new commando for every item in the array and store the result.
I am not sure about what to use for more than 1000 commandos. below is the code how i prepared it now. I trierd the loop with size of 5 items - > this works. But i am worried about run it with 1000 items and how the remote server reacts.
#!/usr/bin/perl -w use Net::OpenSSH; use strict; use warnings; #connection: my $ssh2convey99 = Net::OpenSSH->new('...'); $ssh2convey99->error and die "Couldn't establish SSH connection: ". $ssh2convey99->error; #get some date from remote host and fill array my @ls = $ssh2convey99->capture("disptest | grep -E ' 900 ' | grep -v +1900 | grep -E -v '0 RE' | grep -E -v '0 WE' | grep -E -v '0 WAV' | g +rep -E -v '0 WA' | 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 an store in the matrix foreach my $el (@ls){ $mitzl ++; @split_array = split(/;/,$el); $matrix_array[$mitzl] = [@split_array]; } #including variables and arrays for getting the needed data for all li +st elements my @bt; my @bt_matrix_array; my $length_matrix_array = @matrix_array; #running thru the list and send commando to remote host for every ele +ment. #store all input in new matrix for(my $i = 2;$i <= $length_matrix_array;$i++) { @bt = $ssh2convey99->capture("bt $matrix_array[$i][0]"); $bt_matrix_array[$i-1]=[@bt]; }
this will be the output for 1 element of the loop and the loop will send more than 1000
Welcome to lemans1 (LINUX) Order: 967065/1 Box 282477 Zeit | Stat | Info | Soll + | Ist ----------------+---------+-----------------------------------+------ +-+------- 20140328090153 | AV2 | TLJ3,gerade | + | 20140328090155 | ER01A | TS01,gerade | + | 20140328090204 | LJ7 | TS01,gerade | + | 20140328090213 | S01 | TK1,gerade | + | 20140328090305 | K1 | TS03,gerade | + | 20140328090353 | S03 | TS04,gerade | + | 20140328090415 | S04 | TS06,gerade | 0 + | 230 20140328090438 | S06 | TS08,gerade | + | 20140328090459 | S08 | TS11,gerade | + | 20140328090522 | S11 | TS12,gerade | 0 + | 220 20140328090624 | S12 | TS14,gerade | + | 20140328090645 | S14 | TS16,gerade | + | 20140328090707 | S16 | TS19,gerade | + | 20140328090730 | S19 | TS19,gerade | + | 20140328090911 | S19 | TK3,gerade | 284 + | 310 20140328090954 | K3 | TK5,gerade | + | 20140328091001 | K5 | TK1,gerade | + | 20140328091023 | K1 | TK2,gerade | + | 20140328091033 | K2 | TS28,gerade | + | 20140328091129 | S28 | TS28,gerade | 0 + | 320 20140328091514 | S28 | TS30,gerade | 414 + | 410 20140328091537 | S30 | TS32,gerade | + | 20140328091557 | S32 | TS33,gerade | + | 20140328093457 | S32 | TS35,gerade | + | 20140328093520 | S35 | TER05,weight | 618 + | 550 20140328095704 | S35 | TS20,gerade | 0 + | 580 20140328095806 | S20 | TS22,gerade | + | 20140328095830 | S22 | TS24,gerade | + | 20140328095849 | S24 | TS27,gerade | + | 20140328095912 | S27 | TS27,gerade | + | 20140328100053 | S27 | TK3,gerade | 703 + | 680 20140328100100 | K3 | TWG07,gerade | + | 20140328100201 | WG07 | TSK1,gerade | 0 + | 680 20140328100208 | SK1 | TSK1,gerade | + | 20140328105059 | ESM1 | TERR,lost | + | 20140328110542 | ESM1 | TERR,gerade | + |
what comes after is to write the data in a file during it loops.
thanks for your advice how to do it correctly.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: sending hundreds of commandos on SSH connection
by zentara (Cardinal) on Mar 28, 2014 at 15:57 UTC | |
|
Re: sending hundreds of commandos on SSH connection
by frozenwithjoy (Priest) on Mar 28, 2014 at 14:49 UTC | |
|
Re: sending hundreds of commandos on SSH connection
by kennethk (Abbot) on Mar 28, 2014 at 15:54 UTC | |
|
Re: sending hundreds of commandos on SSH connection
by moritz (Cardinal) on Mar 28, 2014 at 15:16 UTC | |
|
Re: sending hundreds of commandos on SSH connection
by hazylife (Monk) on Mar 28, 2014 at 16:30 UTC | |
|
Re: sending hundreds of commandos on SSH connection
by JGmonk (Initiate) on Mar 28, 2014 at 16:58 UTC | |
by hazylife (Monk) on Mar 28, 2014 at 17:09 UTC | |
by JGmonk (Initiate) on Mar 28, 2014 at 17:04 UTC | |
|
Re: sending hundreds of commandos on SSH connection
by JGmonk (Initiate) on Mar 28, 2014 at 15:38 UTC |