|
From: Steve Kostecke on 5 Oct 2006 22:30 "Tad McClellan" <tadmc(a)augustmail.com> wrote in message news:slrneib43v.9e3.tadmc(a)magna.augustmail.com... > samiam(a)mytrashmail.com <samiam(a)mytrashmail.com> 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?
From: Tad McClellan on 6 Oct 2006 15:04 Steve Kostecke <spamtrap(a)ntp.isc.org> wrote: > "Tad McClellan" <tadmc(a)augustmail.com> wrote in message > news:slrneib43v.9e3.tadmc(a)magna.augustmail.com... >> samiam(a)mytrashmail.com <samiam(a)mytrashmail.com> 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 tadmc(a)augustmail.com Perl programming Fort Worth, Texas
From: samiam on 6 Oct 2006 16:14 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.
From: Tad McClellan on 6 Oct 2006 17:09 samiam(a)mytrashmail.com <samiam(a)mytrashmail.com> 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 tadmc(a)augustmail.com Perl programming Fort Worth, Texas
From: Brian McCauley on 7 Oct 2006 07:09 On Oct 6, 5:03 pm, sam...(a)mytrashmail.com 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__
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 Prev: Problems at writing multiple files Next: Gusetbook with flowers and comment |