Hi, I’ve got a regex issue I am trying to figure out. The situation is I need to pull a file from several servers and return everything past a particular point in that file. The module selection is limited to what is available in a default install. The problem I am having is the regex works the first time. It only returns what I requested, but when it moves on to the next server, and every server thereafter, it returns the entire file. I’ve banged my head at this for the past day or so and just can’t seem to get anywhere. The code is below, generalized for this example.

#!/usr/bin/perl use strict; my $server; my $usrallow = "/etc/opt/quest/vas/users.allow"; my @ssh; my $line; foreach $server(@ARGV) { print "getting cgrpfile from $server\n"; @ssh = `ssh $server /bin/cat $usrallow `; foreach $line (@ssh) { if ($line =~ /line/../\\Z/) { print $line; } } }

The output is below, again somewhat generalized

getting cgrpfile from x.x.x.5 customizations must be after this line. customgrp1 customgrp2 customgrp3 getting cgrpfile from x.x.x.6 #START: Core Groups defaultgrp1 defaultgrp2 defaultgrp3 defaultgrp4 defaultgrp5 defaultgrp6 customizations must be after this line customgrp1 customgrp7 customgrp8 getting cgrpfile from x.x.x.7 #START: Core Groups defaultgrp1 defaultgrp2 defaultgrp3 defaultgrp4 defaultgrp5 defaultgrp6 customizations must be after this line customgrp5 customgrp12 customgrp10

In reply to Regex returns match the first time. It returns everything thereafter by guitarplayer68

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.