adamim has asked for the wisdom of the Perl Monks concerning the following question:
Wondering if anyone can help with some of the code i am writing. My problem is that i need to reset the variable $oknodes back to zero for each "connection" in the array @connectcommand. This array contains ssh connections into a storage server and and counts the number of "OK" from the output of the command. My problem is that after logging into the second storage server the $oknodes variable is adding. E.g after the first storage server the expected output is "4" but after logging into the next one (which as 4 x OK's) $oknodes is then bumped to 8 and gets higher after each connection. I need to be able to reset the $oknodes variable after each ssh connection in the @connectcommand array. Is someone able to provide some insight into this? PS this is only snippets of the entire script so some things may look odd.
######################################### our $HOST1 = "somenode.domain.local"; our $PARNODE1 = "4"; ######################################### our $HOST2 = "somenode1.domain.local"; our $PARNODE2 = "4"; ######################################### my @CONNECTCOMMANDS; if ( length $HOST1 > 0 ) { my $CONNECTCOMMAND1 = "plink.exe -ssh USERNAME\@$HOST1 + -pw PASSWORD"; push (@CONNECTCOMMANDS, "$CONNECTCOMMAND1"); } if ( length $HOST2 > 0 ) { my $CONNECTCOMMAND1 = "plink.exe -ssh USERNAME\@$HOST2 + -pw PASSWORD"; push (@CONNECTCOMMANDS, "$CONNECTCOMMAND2"); } my $CMD = "shownode -s"; my @TEMPHOST; my $TEMPLOG; my $OUTPUT; foreach (@CONNECTCOMMANDS) { @TEMPHOST = split /[\s@]+/, $_; $TEMPHOST = @TEMPHOST[5]; $TEMPLOG = "C:\\osit\\tmp\\$TEMPHOST.CHECK_NODE.tmp"; $OUTPUT = qx{$_ $CMD > "$TEMPLOG"}; open(file, '<:encoding(UTF-8)', $TEMPLOG) or die "Could not open file '$TEMPLOG' $!"; my $oknodes=0; while (my $row = <file>) { if($row =~ /ok/i) { $oknodes++; } + } printf "$TEMPHOST : $oknodes\n"; }
i have updated the code with something that should work
the expected output should be
somenode.domain.local : 4
somenode1.domain.local : 4
what i am getting is,
somenode.domain.local : 4
somenode1.domain.local : 8
as you are probably aware I am not a regular perl coder
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: help with perl variables
by Laurent_R (Canon) on Sep 03, 2015 at 07:20 UTC | |
|
Re: help with perl variables
by davido (Cardinal) on Sep 03, 2015 at 05:21 UTC | |
by AnomalousMonk (Archbishop) on Sep 03, 2015 at 05:40 UTC | |
by davido (Cardinal) on Sep 03, 2015 at 14:54 UTC | |
|
Re: help with perl variables
by AnomalousMonk (Archbishop) on Sep 03, 2015 at 05:20 UTC | |
|
Re: help with perl variables
by AnomalousMonk (Archbishop) on Sep 03, 2015 at 15:35 UTC |