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


In reply to help with perl variables by adamim

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.