Hard or Easy? To find string, then grab criterion matched lines above and below?

Discussion in 'Perl Misc' started by samiam@mytrashmail.com, Oct 5, 2006.

  1. Guest

    Hello,

    I know this is a trivial parse / grep job for any Perl rake worth his
    salt, but does anyone have guidance on how this Perl newbie might pull
    a string from one file and use this string to pull the lines in another
    file out, and also pull the first line before (matching criteria) and
    the first line after (matching criteria.)

    I have described this in detail below.

    At first I thought to use VBScript, but then I realized that Perl is
    portable, doesn't necessarily have to be installed on the server, and
    probably has MUCH better string processing power than VBScript. I also
    considered grep, but still thought I could reuse the Perl solution in
    more places.

    Any input is GREATLY appreciated!

    L,
    S

    ------------

    Summary: I need to find CSR numbers in FILE-A that map to registry key
    entries in FILE-B, and report the pertinent surrounding info.

    Detail:

    I am looking to:

    a.) find the lines in *.aud files with "Fail" in them
    b.) Extract the Section number from the beginning of that same line.
    I'll call this Section number a "CSR #"

    Then use that CSR# to pull from a 2nd *.dsc file :

    a.) Pull first line with CSR#
    b.) Pull the first line above it with anything between two # signs,
    which are section titles like this #Windows Messenger#
    c.) Pull the SECOND registry key instance that is on any line below the
    line with the CSR #
    d.) Out put this data into a CSV file like this:

    CSR#, Section Title, Registry Key

    5.6.1.7.1, Windows Messenger Check, "HLM,
    SOFTWARE\Policies\Microsoft\Messenger\Client,PreventRun,1,INTEGER"

    Since there seem to be commas in the registry key entry, I suppose my
    csv file would need to be delimited by another delimiter recognized by
    Excel, which is where I ultimately want to display my data.

    Below are two data samples like the data from which I will be culling.
    The first sample is from a *.aud audit file.
    The second is from the single DSC program file that either analyzes the
    registry or can also write and change it.

    Basically, I need to report the changes that our program will be making
    to the registry. The audit files show the fail lines, which are lines
    of a servers registry that needs to be brought into compliance.

    server.aud file (audit file)
    5.2.4~Local Printers Shared~NA~PASS~NA
    5.8.1~FTP Server Installed~NA~PASS~NA
    5.6.2~POSIX Subsystem Installed~PASS~PASS~
    5.2.2~Posix Subsystem File Components - Posix.exe Not Found~NA~PASS~NA
    5.2.2~Posix Subsystem File Components - Psxss.exe Not Found~NA~PASS~NA
    5.2.2~Posix Subsystem File Components - Psxdll.dll Not Found~NA~PASS~NA
    5.6.1.1~NetMeeting Disable Remote Desktop Sharing~FAIL~FAIL~
    5.6.1.2~IE Security Zones are Local Only~FAIL~FAIL~
    5.6.1.2.2~Allow User to Change IE Sec Policy~FAIL~FAIL~
    5.6.1.2.3~IE Security Zones Map Editing~FAIL~FAIL~
    5.6.1.2.4~IE Proxy Settings Set Per User~FAIL~FAIL~
    5.6.1.2.5~IE Automatic Installs Disabled~FAIL~FAIL~
    5.6.1.2.6~IE Software Update Check~FAIL~FAIL~

    -----------------------------

    analyze.dsc (script for analyzing/writing to registry)

    # Windows Messenger #
    dialog set,text1,"5.6.1.7.1 Windows Messenger Check"
    dialog set,text2,"5.6.1.7.1 Do Not Allow Windows Messenger to be Run"
    %%before =
    @REGREAD(HLM,SOFTWARE\Policies\Microsoft\Messenger\Client,PreventRun,)
    REGISTRY
    WRITE,HLM,SOFTWARE\Policies\Microsoft\Messenger\Client,PreventRun,1,INTEGER
     
    , Oct 5, 2006
    #1
    1. Advertising

  2. Guest

    , Oct 5, 2006
    #2
    1. Advertising

  3. <> wrote:

    > I know this is a trivial parse / grep job for any Perl rake worth his
    > salt, but does anyone have guidance on how this Perl newbie might pull
    > a string from one file and use this string to pull the lines in another
    > file out, and also pull the first line before (matching criteria) and
    > the first line after (matching criteria.)



    If you show us the code you have so far, we will help you fix it.


    > At first I thought to use VBScript, but then I realized that Perl is
    > portable, doesn't necessarily have to be installed on the server, and



    What "server"?

    A server is not normally required to run Perl programs.

    Is this a stealth CGI question?

    If it is a CGI question, then you _do_ need to have perl installed
    on the web server.


    > Summary: I need to find CSR numbers in FILE-A that map to registry key
    > entries in FILE-B, and report the pertinent surrounding info.



    None of the failed CSR numbers in your example FILE-A map to any registry
    key entries in FILE-B, so the program must make no output...


    > a.) find the lines in *.aud files with "Fail" in them
    > b.) Extract the Section number from the beginning of that same line.



    Here's how to do that part:

    -----------------------------------------------
    #!/usr/bin/perl
    use warnings;
    use strict;

    while ( <DATA>) {
    my($csr, @fields) = split /~/;
    next unless grep { $_ eq 'FAIL' } @fields;
    print "$csr\n";

    }

    __DATA__
    5.2.4~Local Printers Shared~NA~PASS~NA
    5.8.1~FTP Server Installed~NA~PASS~NA
    5.6.2~POSIX Subsystem Installed~PASS~PASS~
    5.2.2~Posix Subsystem File Components - Posix.exe Not Found~NA~PASS~NA
    5.2.2~Posix Subsystem File Components - Psxss.exe Not Found~NA~PASS~NA
    5.2.2~Posix Subsystem File Components - Psxdll.dll Not Found~NA~PASS~NA
    5.6.1.1~NetMeeting Disable Remote Desktop Sharing~FAIL~FAIL~
    5.6.1.2~IE Security Zones are Local Only~FAIL~FAIL~
    5.6.1.2.2~Allow User to Change IE Sec Policy~FAIL~FAIL~
    5.6.1.2.3~IE Security Zones Map Editing~FAIL~FAIL~
    5.6.1.2.4~IE Proxy Settings Set Per User~FAIL~FAIL~
    5.6.1.2.5~IE Automatic Installs Disabled~FAIL~FAIL~
    5.6.1.2.6~IE Software Update Check~FAIL~FAIL~
    -----------------------------------------------



    > Then use that CSR# to pull from a 2nd *.dsc file :



    I would have done that part too, but I could not be troubled
    to come up with a meaningful data file (and neither could you,
    it would appear).


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Oct 6, 2006
    #3
  4. "Tad McClellan" <> wrote in message
    news:...
    > <> wrote:
    >
    >> I know this is a trivial parse / grep job for any Perl rake worth his
    >> salt, but does anyone have guidance on how this Perl newbie might pull
    >> a string from one file and use this string to pull the lines in another
    >> file out, and also pull the first line before (matching criteria) and
    >> the first line after (matching criteria.)

    >
    >
    > If you show us the code you have so far, we will help you fix it.
    >
    >
    >> At first I thought to use VBScript, but then I realized that Perl is
    >> portable, doesn't necessarily have to be installed on the server, and

    >
    >
    > What "server"?
    >
    > A server is not normally required to run Perl programs.
    >
    > Is this a stealth CGI question?


    His question was obviously pertaining to Perl being used for a file parsing
    solution. The question itself had nothing to do with CGI and I think you
    knew that.

    > If it is a CGI question, then you _do_ need to have perl installed
    > on the web server.


    No, not necessarily. There are several way to "compile" a Perl script into a
    standalone executable (perl2bin, perl2exe, etc. Also there's ActiveState's
    PerlEXE, part of the Perl Dev Kit.) Regardless of the OS, if you can make it
    into a standalone binary, it's only a matter of properly configuring the
    server to run it, and no Perl installation is needed (and yes I've tested.)

    >> Summary: I need to find CSR numbers in FILE-A that map to registry key
    >> entries in FILE-B, and report the pertinent surrounding info.

    >
    >
    > None of the failed CSR numbers in your example FILE-A map to any registry
    > key entries in FILE-B, so the program must make no output...


    Maybe just a bad example and not necessarily the only data that'll be
    operated on?
     
    Steve Kostecke, Oct 6, 2006
    #4
  5. Guest

    Hi Tad,

    Thanks for the reply.

    Your code snippet is leaner and more elegant than the labyrinthine code
    I imagined necessary.

    Sorry about my second data file not reflecting a match to the 1st. Per
    your rebuke I have amended my ways: Here are links to data file
    examples with matching data points:

    http://home.comcast.net/~tankomail/test.dsc
    http://home.comcast.net/~tankomail/server1.aud

    And below is a snippet of FILE-A data which matches FILE-B data.

    For instance - the fail line 5.4.6.24 in FILE-B matches the # cached
    logon credentials # section in FILE-A vis-a-vis the section containing
    the same 5.4.6.24 CSR#.

    FILE-A is no more than sections delimited by #Section Title# , the
    Registry key that needs to be changed, and identified by CSR numbers.

    The goal is to pull the registry entry from each failed CSR section
    (Identified in FILE-B) and pull from FILE-A:
    1.) #section title#
    2.) CSR#
    3.) %%before and %% after registry keys

    and push this data into CSV format for viewing with Excel.

    --------------------------
    FILE-B Aud file:

    5.7.1.2~Password Expires Requirement~FAIL~FAIL~
    5.4.6.62~Force Unlock Logon~FAIL~FAIL~
    5.4.6.24~Cached logon credentials~FAIL~FAIL~1010
    5.4.6.27~Smart Card Behavior~FAIL~FAIL~11
    5.4.6.20~Auto Admin Login Settings~PASS~PASS~00
    5.4.6.9~Sharing of Devices - Floppys~PASS~PASS~11
    5.4.6.9~Sharing of Devices - CDRoms~PASS~PASS~11
    5.4.6.7~Sharing of Devices - DASD~PASS~PASS~00
    5.4.6.16~IPSec Security for Kerberos RSVP Traffic~PASS~PASS~11
    5.4.6.17~Hide Computer Name~FAIL~FAIL~
    ---------------------------

    Find the fail lines, get the CSR at the beginning of the line and match
    to registry change section in FILE-A
    -------------------------
    FILE-A dsc file:

    # cached logon credentials #
    dialog set,text1,"5.4.6.24 Cached logon credentials" **********
    dialog set,text2,"5.4.6.24 Cached logon credentials"
    %%before = @REGREAD(HLM,SOFTWARE\Microsoft\Windows
    NT\CurrentVersion\Winlogon,CachedLogonsCount,)
    REGISTRY WRITE,HLM,SOFTWARE\Microsoft\Windows
    NT\CurrentVersion\Winlogon,CachedLogonsCount,2
    %%after = @REGREAD(HLM,SOFTWARE\Microsoft\Windows
    NT\CurrentVersion\Winlogon,CachedLogonsCount,)
    %%stat = FAIL
    %%stat2 = FAIL
    if @equal(%%before,"2")
    %%stat = PASS
    end
    if @equal(%%after,"2")
    %%stat2 = PASS
    end
    list add,debug,"Cached logon credentials:Setting Before Run" %%before
    "Setting After Run:" %%after
    list add,log,"5.4.6.24~Cached logon
    credentials~"%%stat"~"%%stat2"~"%%before%%after
    list savefile,log,%%logfile
    list savefile,debug,%%debugfile
    wait 0.2

    :checktwentyseven
    %%check = @INIREAD(checks,checktwentyseven)
    if @equal(%%check,off)
    goto checktwentyeight
    end
    ---------------------------

    Thanks for your help Tad!

    L,
    Sam

    Tad McClellan wrote:
    > <> wrote:
    >
    > > I know this is a trivial parse / grep job for any Perl rake worth his
    > > salt, but does anyone have guidance on how this Perl newbie might pull
    > > a string from one file and use this string to pull the lines in another
    > > file out, and also pull the first line before (matching criteria) and
    > > the first line after (matching criteria.)

    >
    >
    > If you show us the code you have so far, we will help you fix it.
    >
    >
    > > At first I thought to use VBScript, but then I realized that Perl is
    > > portable, doesn't necessarily have to be installed on the server, and

    >
    >
    > What "server"?
    >
    > A server is not normally required to run Perl programs.
    >
    > Is this a stealth CGI question?
    >
    > If it is a CGI question, then you _do_ need to have perl installed
    > on the web server.
    >
    >
    > > Summary: I need to find CSR numbers in FILE-A that map to registry key
    > > entries in FILE-B, and report the pertinent surrounding info.

    >
    >
    > None of the failed CSR numbers in your example FILE-A map to any registry
    > key entries in FILE-B, so the program must make no output...
    >
    >
    > > a.) find the lines in *.aud files with "Fail" in them
    > > b.) Extract the Section number from the beginning of that same line.

    >
    >
    > Here's how to do that part:
    >
    > -----------------------------------------------
    > #!/usr/bin/perl
    > use warnings;
    > use strict;
    >
    > while ( <DATA>) {
    > my($csr, @fields) = split /~/;
    > next unless grep { $_ eq 'FAIL' } @fields;
    > print "$csr\n";
    >
    > }
    >
    > __DATA__
    > 5.2.4~Local Printers Shared~NA~PASS~NA
    > 5.8.1~FTP Server Installed~NA~PASS~NA
    > 5.6.2~POSIX Subsystem Installed~PASS~PASS~
    > 5.2.2~Posix Subsystem File Components - Posix.exe Not Found~NA~PASS~NA
    > 5.2.2~Posix Subsystem File Components - Psxss.exe Not Found~NA~PASS~NA
    > 5.2.2~Posix Subsystem File Components - Psxdll.dll Not Found~NA~PASS~NA
    > 5.6.1.1~NetMeeting Disable Remote Desktop Sharing~FAIL~FAIL~
    > 5.6.1.2~IE Security Zones are Local Only~FAIL~FAIL~
    > 5.6.1.2.2~Allow User to Change IE Sec Policy~FAIL~FAIL~
    > 5.6.1.2.3~IE Security Zones Map Editing~FAIL~FAIL~
    > 5.6.1.2.4~IE Proxy Settings Set Per User~FAIL~FAIL~
    > 5.6.1.2.5~IE Automatic Installs Disabled~FAIL~FAIL~
    > 5.6.1.2.6~IE Software Update Check~FAIL~FAIL~
    > -----------------------------------------------
    >
    >
    >
    > > Then use that CSR# to pull from a 2nd *.dsc file :

    >
    >
    > I would have done that part too, but I could not be troubled
    > to come up with a meaningful data file (and neither could you,
    > it would appear).
    >
    >
    > --
    > Tad McClellan SGML consulting
    > Perl programming
    > Fort Worth, Texas
     
    , Oct 6, 2006
    #5
  6. Guest

    Hi Tad,

    Links to the complete data files and a detailed description of my
    simple data mining are in my first and second post.

    Here is my perl script solution so far - at the end of this post.

    I am a crude programmer and so I can't attest for the elegance of this
    code or if it's even close to efficient. This code is bits and pieces I
    have put together looking at examples on the net. It mostly works.

    I haven't been able to get it to put both the %%before and %%after
    sections into the csv file.

    I would also like to pull the descriptive title of the registry key
    into the CSV file, ie. "Checking Netmeeting - Disable Remote Desktop
    Sharing" It comes at the end of the lines containing the CSR# such as
    5.6.1.1

    That part is tricky, at least to this noob.

    Can anyone tell me how to add both the %%before and %%after as well as
    the key description to my csv file?

    Thanks!

    L,
    Sam

    -------sample data-----------

    # NETMEETING REG SETTING #
    dialog set,text1,"5.6.1.1 Checking Netmeeting - Disable Remote Desktop
    Sharing"
    dialog set,text2,"5.6.1.1 Checking Netmeeting - Disable Remote Desktop
    Sharing"
    %%before =
    @REGREAD(HLM,SOFTWARE\Policies\Microsoft\Conferencing,NoRDS,)
    REGISTRY
    WRITE,HLM,SOFTWARE\Policies\Microsoft\Conferencing,NoRDS,1,INTEGER
    %%after = @REGREAD(HLM,SOFTWARE\Policies\Microsoft\Conferencing,NoRDS,)
    %%stat = FAIL
    %%stat2 = FAIL
    if @equal(%%before,"1")
    %%stat = PASS
    end
    if @equal(%%after,"1")
    %%stat2 = PASS
    end
    list add,debug,"5.6.1.1:Setting Before Run" %%before "Setting After
    Run:" %%after
    list add,log,"5.6.1.1~NetMeeting Disable Remote Desktop
    Sharing~"%%stat"~"%%stat2"~"%%before%%after
    list savefile,log,%%logfile
    list savefile,debug,%%debugfile
    wait 0.2

    :checkseven
    %%check = @INIREAD(checks,checkseven)
    if @equal(%%check,off)
    goto checkeight
    end

    --------end sample data------------

    ---------Script So Far-------------
    #Create a couple of lookup hashes
    open ANALYZE, 'analyze.dsc';
    while(<ANALYZE>) {
    $section = $1 if /^#\s+(.*)?\s+#/;
    $rule_no = $1 if /^dialog set,text1,\"([.1234567890]*)/;
    if( /^REGISTRY WRITE,(.*)/ ) {
    $regkey{$rule_no} = $1;
    $sect{$rule_no} = $section;
    }
    }
    close ANALYZE;

    #Scan the Audit file for failures
    open AUDITFILE, 'server.aud';
    open CSVFILE, '>logfile.csv';
    print CSVFILE "CSR #,Section Title,Registry Key\n";
    while(<AUDITFILE>) {
    if(/^(.*?)~.*~FAIL~/) {
    $csr = $1;
    $section_title = $sect{$csr};
    $registry_key = $regkey{$csr};
    if( $section_title ne "" ) {
    print CSVFILE "\"$csr\",\"$section_title\",\"$registry_key\"\n";
    } else {
    print "Fail code $csr not found in analyze.dsc\n";
    }
    }
    }
    close AUDITFILE;
    close CSVFILE;
     
    , Oct 6, 2006
    #6
  7. Steve Kostecke <> wrote:
    > "Tad McClellan" <> wrote in message
    > news:...
    >> <> wrote:


    >>> At first I thought to use VBScript, but then I realized that Perl is
    >>> portable, doesn't necessarily have to be installed on the server, and

    >>
    >>
    >> What "server"?
    >>
    >> A server is not normally required to run Perl programs.
    >>
    >> Is this a stealth CGI question?

    >
    > His question was obviously pertaining to Perl being used for a file parsing
    > solution. The question itself had nothing to do with CGI and I think you
    > knew that.



    Yes, I did.

    But it appeared that the OP did not. Now he does.


    >>> Summary: I need to find CSR numbers in FILE-A that map to registry key
    >>> entries in FILE-B, and report the pertinent surrounding info.

    >>
    >>
    >> None of the failed CSR numbers in your example FILE-A map to any registry
    >> key entries in FILE-B, so the program must make no output...

    >
    > Maybe just a bad example and not necessarily the only data that'll be
    > operated on?



    My point was exactly that it _was_ a bad example.


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Oct 6, 2006
    #7
  8. Guest

    But in subsequent posts I've clearly rectified the non-matching data
    yes?

    And I knew that Perl did not need to be installed for my purposes -
    that's the first thing I checked since these are important production
    servers.

    At the end of this post is the sum of my initial research on that
    matter.

    If my last 2 posts are reviewed...at this point...I am simply looking
    to modify my script to

    1.) add the %%before and %%after registry sections to my CSV
    2.) Add the detailed registry description to a csv field as well. Ergo,
    I want to pull the "Checking IE Security Zones" elements into the CSV
    as seen from a data snippet below.

    dialog set,text2,"5.6.1.2 Checking IE Security Zones"

    Any input on this?

    Thanks!

    L,
    Sam


    ------------------------------------------------------------------------------------------------------
    How to run perl without installing it
    http://www.oreillynet.com/pub/a/network/2003/11/18/activedir_ckbk.html

    * Perl Does not Require installation

    This suggests perl needs to be installed on any machine a perl script
    needs to run on. Not so.

    Easiest way around this is to install Activestate perl on ONE machine
    with all your favorite 3rd party modules and copy the "c:\perl" folder
    to a shared network location and call your scripts from a oneliner
    batch file like so.

    \\server\perl\bin\perl.exe \\server\scripts\myscript.pl

    or wrap it in a batch file like this:

    @echo off
    \\server\perl\bin\perl.exe -x %0 %*

    :: the above command tells the perl interpreter to
    :: strip off text before #!perl line and treat everything
    :: afterward like a perl script!

    goto endofperl

    #!perl

    print "this rocks, this portable script will \n";
    print "run on any machine in the network. \n";
    print "No perl install required on target machine \n";

    __END__
    :endofperl

    Also, their are many ways to compile scripts into exe's for users and
    make mini-perl interpreters (like a 2 meg perl.exe interpreter) so you
    can send open-source scripts to other admins to edit/plagiarize. No
    need to install 50+ megs of perl on any machine + modules unless you
    are developing.
     
    , Oct 6, 2006
    #8
  9. <> wrote:
    > But in subsequent posts I've clearly rectified the non-matching data
    > yes?



    Yes.

    But I only have time for 3-minute answers right now.

    Maybe I can add something this evening or over the weekend.


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Oct 6, 2006
    #9
  10. On Oct 6, 5:03 pm, wrote:
    >
    > Here is my perl script solution so far - at the end of this post.


    A very good start.

    > I am a crude programmer and so I can't attest for the elegance of this
    > code or if it's even close to efficient. This code is bits and pieces I
    > have put together looking at examples on the net. It mostly works.


    I've put "use strict" and "use warnings" at the top and used lexical
    variables and put or die on all your open()s. This makes your code look
    a lot less crude.

    Oh, and I simplified a couple of the regex.

    > I haven't been able to get it to put both the %%before and %%after
    > sections into the csv file.


    Right, you had two parallel hashes. If you added two more you've have
    four. By my "rule of three" that means you'd be doing it wrong.

    I have replaced your paralell hashes by a has containing records. The
    record is actually implemented as a hash, but conceptually it's being
    (ab)uses as a record structure not an associative array. This is normal
    practice in Perl.

    It also actually makes the code simpler because I can attach the record
    into the container hash before it's complete.

    > I would also like to pull the descriptive title of the registry key
    > into the CSV file, ie. "Checking Netmeeting - Disable Remote Desktop
    > Sharing" It comes at the end of the lines containing the CSR# such as
    > 5.6.1.1
    >
    > That part is tricky, at least to this noob.


    I don't get why that's tricky

    You managed to pull out the CSR with a pattern. Extending the pattern
    to get the description too is trivial.

    #!perl
    use strict;
    use warnings;

    my %sect;

    {
    #Create a couple of lookup hashes
    my $record;

    open my $analyze, '<', 'test.dsc' or die $!;
    while(<$analyze>) {
    $record = { section => $1 } if /^#\s+(.*)\s+#/;
    $sect{$1} = $record if /^dialog set,text1,\"([.0-9]+)/;
    $record->{regkey}= $1 if /^REGISTRY WRITE,(.*)/;
    $record->{$1} = $2 if /^%%(after|before) = \@REGREAD\((.*)\)/;
    }

    close $analyze;
    }

    #Scan the Audit file for failures
    open my $auditfile, '<', 'server1.aud' or die $!;
    open my $csvfile, '>', 'logfile.csv' or die $!;

    print $csvfile "CSR #,Decriprion,Section Title,Registry
    Key,Before,After\n";
    while(<$auditfile>) {
    if( my ($csr,$desc) = /^(.*?)~([^~]*).*~FAIL~/) {
    if ( my $record = $sect{$csr} ) {
    print $csvfile join (',',map {"\"$_\""} $csr, $desc,
    @$record{'section','regkey','before','after'}),"\n";
    } else {
    print "Fail code $csr not found in analyze.dsc\n";
    }
    }
    }

    close $auditfile;
    close $csvfile;

    __END__
     
    Brian McCauley, Oct 7, 2006
    #10
  11. Steve K. Guest

    Tad McClellan wrote:
    >Steve Kostecke <> wrote:
    >> "Tad McClellan" <> wrote in message
    >> news:...
    >>> <> wrote:

    >
    >>>> At first I thought to use VBScript, but then I realized that Perl
    >>>> is portable, doesn't necessarily have to be installed on the
    >>>> server, and
    >>>
    >>>
    >>> What "server"?
    >>>
    >>> A server is not normally required to run Perl programs.
    >>>
    >>> Is this a stealth CGI question?

    >>
    >> His question was obviously pertaining to Perl being used for a file
    >> parsing solution. The question itself had nothing to do with CGI and
    >> I think you knew that.

    >
    >
    > Yes, I did.
    >
    > But it appeared that the OP did not. Now he does.


    What made you think he did not?? Simply because he said "server" some
    how automagically translates into your min into "web server" ? Has it
    even occurred to you he could of simply meant a remote server he has
    been working on? For instance, you SSH or Remote-Desktop/VNC in and you
    work; not exactly a new concept. This can be for any number of purposes,
    and he never said one thing abut www, web, http, nor cgi.

    Lets take a look at what he DID say:

    wrote:
    > Hello,
    >
    > I know this is a trivial parse / grep job for any Perl rake worth his
    > salt,


    Hmm, "trivial parse / grep job ", looks right up Perl's alley.

    > but does anyone have guidance on how this Perl newbie might pull
    > a string from one file and use this string to pull the lines in
    > another file out, and also pull the first line before (matching
    > criteria) and the first line after (matching criteria.)


    Text parsing stuff, still very valid for Perl, don'cha think?

    > I have described this in detail below.
    >
    > At first I thought to use VBScript,


    VBScript has many applications outside of web scripting. He makes no
    mention of web, http, or cgi so no reason to go there. (See "Scripting
    Host" on Windows.)

    > but then I realized that Perl is
    > portable, doesn't necessarily have to be installed on the server, and
    > probably has MUCH better string processing power than VBScript.


    In this context, he could of either meant a "remove server" or he could
    of been referring to any old box. Still no mention of anything web
    related.

    > I also considered grep, but still thought I could reuse the Perl
    > solution in more places.


    So please tell me how anything he said can be seen as a CGI question,
    and how it was even remotely fair to accuse him like you did of making a
    "stealth CGI question" when everything he wrote was HOW to do some
    "trivial parse / grep job" with Perl. Even with CGI questions it's often
    been said it will go answered if the question is still _directed_ at the
    Perl side of things, so I really see no point at all as trying to paint
    him as trying to do something wrong with words like "stealth", as if
    you're just simply witch hunting.
     
    Steve K., Oct 7, 2006
    #11
  12. Guest

    Hi Steve,

    Very able defense. Thank you.

    You are, of course, correct: There is no cgi or Web Server involved in
    this equation. I didn't know "cgi was off limits" or taboo in this
    group. Why is cgi a no-no?

    My application of this perl parser is to report the output of security
    related registry changes on voice recognition servers. They are stand
    alone w2k boxes being brought into lock-down compliance.

    Thanks to someone named Brigmar over on Tek-Tips, I have a very elegant
    solution, far more terse than I imagined. In little over 20 lines of
    code, he conditionally pulls data from FILE-A and uses this data to
    conditionally pull from FILE-B and then posts it all in a CSV file. Do
    you think his code is especially economical and clean?

    http://home.comcast.net/~tankomail/Brigmar_Report_script.pl

    The only thing I have failed at doing is pulling the:
    %%before and %% after registry keys and putting these into additional
    columns in the CSV file.

    I figure with this model, there is a whole world of pasing tasks I
    could do with this as my code base.

    Do you have a line into how I could add the two additional column
    values?

    The simple project is summed at the bottom as well as links to the 2
    data files, Brigmar's excellent script on which all is based and a few
    pasted data samples from the 2 linked data files.

    Thanks for your input!

    L,
    S
    -----------------------------------------
    DATA FILES AND INITIAL SCRIPT FROM BRIGMAR from Tek Tips.

    http://home.comcast.net/~tankomail/test.dsc FILE-A data
    http://home.comcast.net/~tankomail/server1.aud FILE-B data
    http://home.comcast.net/~tankomail/Brigmar_Report_script.pl Brigmar
    Script
    http://home.comcast.net/~tankomail/logfile.csv - The CSV files the
    script creates

    Below is a snippet of FILE-A data which matches FILE-B data.

    For instance - the fail line 5.4.6.24 in FILE-B matches the # cached
    logon credentials # section in FILE-A vis-a-vis the section
    containing the same 5.4.6.24 CSR#.

    FILE-A is no more than sections delimited by #Section Title# , the
    Registry key that needs to be changed, and identified by CSR numbers.

    The goal is to pull the registry entry from each failed CSR section
    (Identified in FILE-B) and pull from FILE-A:
    1.) #section title#
    2.) CSR#
    3.) %%before and %% after registry keys

    and push this data into CSV format for viewing with Excel.

    --------------------------
    FILE-B Aud file:

    5.7.1.2~Password Expires Requirement~FAIL~FAIL~
    5.4.6.62~Force Unlock Logon~FAIL~FAIL~
    5.4.6.24~Cached logon credentials~FAIL~FAIL~1010
    5.4.6.27~Smart Card Behavior~FAIL~FAIL~11
    5.4.6.20~Auto Admin Login Settings~PASS~PASS~00
    5.4.6.9~Sharing of Devices - Floppys~PASS~PASS~11
    5.4.6.9~Sharing of Devices - CDRoms~PASS~PASS~11
    5.4.6.7~Sharing of Devices - DASD~PASS~PASS~00
    5.4.6.16~IPSec Security for Kerberos RSVP Traffic~PASS~PASS~11
    5.4.6.17~Hide Computer Name~FAIL~FAIL~
    ---------------------------

    Find the fail lines, get the CSR at the beginning of the line and match
    to registry change section in FILE-A
    -------------------------
    FILE-A dsc file:

    # cached logon credentials #
    dialog set,text1,"5.4.6.24 Cached logon
    credentials" **********Wish to add these descriptions to csv
    dialog set,text2,"5.4.6.24 Cached logon credentials"
    %%before = @REGREAD(HLM,SOFTWARE\Microsoft\Windows
    NT\CurrentVersion\Winlogon,CachedLogonsCount,)
    REGISTRY WRITE,HLM,SOFTWARE\Microsoft\Windows
    NT\CurrentVersion\Winlogon,CachedLogonsCount,2
    %%after = @REGREAD(HLM,SOFTWARE\Microsoft\Windows
    NT\CurrentVersion\Winlogon,CachedLogonsCount,)
    %%stat = FAIL
    %%stat2 = FAIL
    if @equal(%%before,"2")
    %%stat = PASS
    end
    if @equal(%%after,"2")
    %%stat2 = PASS
    end
    list add,debug,"Cached logon credentials:Setting Before Run" %%before
    "Setting After Run:" %%after
    list add,log,"5.4.6.24~Cached logon
    credentials~"%%stat"~"%%stat2"~"%%before%%after
    list savefile,log,%%logfile
    list savefile,debug,%%debugfile
    wait 0.2

    :checktwentyseven
    %%check = @INIREAD(checks,checktwentyseven)
    if @equal(%%check,off)
    goto checktwentyeight
    end
    ---------------------------
    Steve K. wrote:
    > Tad McClellan wrote:
    > >Steve Kostecke <> wrote:
    > >> "Tad McClellan" <> wrote in message
    > >> news:...
    > >>> <> wrote:

    > >
    > >>>> At first I thought to use VBScript, but then I realized that Perl
    > >>>> is portable, doesn't necessarily have to be installed on the
    > >>>> server, and
    > >>>
    > >>>
    > >>> What "server"?
    > >>>
    > >>> A server is not normally required to run Perl programs.
    > >>>
    > >>> Is this a stealth CGI question?
    > >>
    > >> His question was obviously pertaining to Perl being used for a file
    > >> parsing solution. The question itself had nothing to do with CGI and
    > >> I think you knew that.

    > >
    > >
    > > Yes, I did.
    > >
    > > But it appeared that the OP did not. Now he does.

    >
    > What made you think he did not?? Simply because he said "server" some
    > how automagically translates into your min into "web server" ? Has it
    > even occurred to you he could of simply meant a remote server he has
    > been working on? For instance, you SSH or Remote-Desktop/VNC in and you
    > work; not exactly a new concept. This can be for any number of purposes,
    > and he never said one thing abut www, web, http, nor cgi.
    >
    > Lets take a look at what he DID say:
    >
    > wrote:
    > > Hello,
    > >
    > > I know this is a trivial parse / grep job for any Perl rake worth his
    > > salt,

    >
    > Hmm, "trivial parse / grep job ", looks right up Perl's alley.
    >
    > > but does anyone have guidance on how this Perl newbie might pull
    > > a string from one file and use this string to pull the lines in
    > > another file out, and also pull the first line before (matching
    > > criteria) and the first line after (matching criteria.)

    >
    > Text parsing stuff, still very valid for Perl, don'cha think?
    >
    > > I have described this in detail below.
    > >
    > > At first I thought to use VBScript,

    >
    > VBScript has many applications outside of web scripting. He makes no
    > mention of web, http, or cgi so no reason to go there. (See "Scripting
    > Host" on Windows.)
    >
    > > but then I realized that Perl is
    > > portable, doesn't necessarily have to be installed on the server, and
    > > probably has MUCH better string processing power than VBScript.

    >
    > In this context, he could of either meant a "remove server" or he could
    > of been referring to any old box. Still no mention of anything web
    > related.
    >
    > > I also considered grep, but still thought I could reuse the Perl
    > > solution in more places.

    >
    > So please tell me how anything he said can be seen as a CGI question,
    > and how it was even remotely fair to accuse him like you did of making a
    > "stealth CGI question" when everything he wrote was HOW to do some
    > "trivial parse / grep job" with Perl. Even with CGI questions it's often
    > been said it will go answered if the question is still _directed_ at the
    > Perl side of things, so I really see no point at all as trying to paint
    > him as trying to do something wrong with words like "stealth", as if
    > you're just simply witch hunting.
     
    , Oct 9, 2006
    #12
  13. writes:

    > You are, of course, correct: There is no cgi or Web Server involved in
    > this equation. I didn't know "cgi was off limits" or taboo in this
    > group. Why is cgi a no-no?


    If the answer to your question would be the same if you were writing in
    some other language, then it's not a Perl question, and therefore off-
    topic here.

    A contrived example: "I print some HTML from my Perl CGI. The page renders
    fine in FireFox, but not in IE." That's not a Perl question, it's an HTML
    question; the answer is "fix the HTML". The fact that the HTML is the
    output from a Perl script doesn't make it a Perl question.

    Another contrived example: "I'm returning the correct MIME type from my
    CGI script, but IE ignores that and parses it as HTML anyway." Once again,
    that's not a Perl question, since IE would be doing precisely the same
    thing if your CGI were written in Python, Ruby, or whatever.

    It isn't just a question of netiquette and/or courtesy either. Understanding
    a problem is a critical step in solving it. Quite often, in the process of
    narrowing down the exact nature of a bug, in preparation of deciding which
    group to ask questions in, I find that I've found the bug myself and don't
    need to ask in any group at all.

    sherm--

    --
    Web Hosting by West Virginians, for West Virginians: http://wv-www.net
    Cocoa programming in Perl: http://camelbones.sourceforge.net
     
    Sherm Pendley, Oct 9, 2006
    #13
  14. Guest

    Ahhh...of course. Makes sense. Thanks!

    Just to be clear, my question is in fact, strictly a Perl parsing
    question :)

    L,
    S


    Sherm Pendley wrote:
    > writes:
    >
    > > You are, of course, correct: There is no cgi or Web Server involved in
    > > this equation. I didn't know "cgi was off limits" or taboo in this
    > > group. Why is cgi a no-no?

    >
    > If the answer to your question would be the same if you were writing in
    > some other language, then it's not a Perl question, and therefore off-
    > topic here.
    >
    > A contrived example: "I print some HTML from my Perl CGI. The page renders
    > fine in FireFox, but not in IE." That's not a Perl question, it's an HTML
    > question; the answer is "fix the HTML". The fact that the HTML is the
    > output from a Perl script doesn't make it a Perl question.
    >
    > Another contrived example: "I'm returning the correct MIME type from my
    > CGI script, but IE ignores that and parses it as HTML anyway." Once again,
    > that's not a Perl question, since IE would be doing precisely the same
    > thing if your CGI were written in Python, Ruby, or whatever.
    >
    > It isn't just a question of netiquette and/or courtesy either. Understanding
    > a problem is a critical step in solving it. Quite often, in the process of
    > narrowing down the exact nature of a bug, in preparation of deciding which
    > group to ask questions in, I find that I've found the bug myself and don't
    > need to ask in any group at all.
    >
    > sherm--
    >
    > --
    > Web Hosting by West Virginians, for West Virginians: http://wv-www.net
    > Cocoa programming in Perl: http://camelbones.sourceforge.net
     
    , Oct 9, 2006
    #14
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    3
    Views:
    415
    Vyacheslav Kononenko
    Jan 10, 2005
  2. bullockbefriending bard

    matching objects by a tuple field criterion

    bullockbefriending bard, Jun 10, 2007, in forum: Python
    Replies:
    9
    Views:
    283
    John Machin
    Jun 10, 2007
  3. Replies:
    0
    Views:
    297
  4. mike
    Replies:
    15
    Views:
    188
    Anno Siegel
    May 21, 2004
  5. kiran
    Replies:
    12
    Views:
    1,128
    Scott Sauyet
    Dec 7, 2011
Loading...

Share This Page