[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 163
  • Last Modified:

Parse revisions from log file

I need to verify file revisions in a log file that I'm writing out with a perl script.
The log file, has the following lines in it, among other things:

<===cut from log===>
File: Helpus/All/build.xml
before Release20060411_01:
   Sticky Tag:            Q20060330 (revision: 1.1)

after Release20060411_01
   Sticky Tag:            Release20060404_01 (revision: 1.2)
<===cut from log===>

I'd like to add a revision audit function to my current perl script.
I need to look for
1)revisions going backwards ("before" "revision: 1.1" and "after" "revision:1.0")...
...as well as
2)revision hopping (before 1.1, after 1.3).

I need to audit each file in the log file.
Each file has an entry similar to the build.xml <=cut=> from above.
If the file is indicated in the log as violating #1 or #2, I like to write the file name listed in the log after "File:" to an alert text file.

Thanks for any help!
I haven't had time to hack anything together and I like learn from the experts anyway.


0
jwcorbett
Asked:
jwcorbett
  • 10
  • 9
1 Solution
 
ozoCommented:
I'm not quite sure what it is you want to do.
Given the above cut from log as input, what would you want the output of the sctipt to be?
0
 
jwcorbettAuthor Commented:
The output would depend on the revisions listed for the given filename.
So, in the cut, the filename (and path) is Helpus/All/build.xml
I would want "Helpus/All/build.xml" listed in a new text file if the revisions for it either go backward, or hop (skip) a revision.
0
 
ozoCommented:
So, given the above cut from log, you would not have any output?
Would (before 1.9, after 2.0) be a skip?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
jwcorbettAuthor Commented:
Correct, the cut from above would not have output...
No, before 1.9, after 2.0 would not be a skip, it would be valid.

So the two examples where I'd need an alert text file written to would be:
Skip (revision 1.2 is skipped):
<===cut from log===>
File: Helpus/All/build.xml
before Release20060411_01:
   Sticky Tag:          Q20060330 (revision: 1.1)

after Release20060411_01
   Sticky Tag:          Release20060404_01 (revision: 1.3)
<===cut from log===>

and backwards:
<===cut from log===>
File: Helpus/All/build.xml
before Release20060411_01:
   Sticky Tag:          Q20060330 (revision: 1.3)

after Release20060411_01
   Sticky Tag:          Release20060404_01 (revision: 1.2)
<===cut from log===>

Hope this helps and thanks for yours!
0
 
ozoCommented:
I'm still not quite sure how skip is defined.
would 1.85 to 2.01 be a skip?
would 1.9 to 1.10 be a skip?  Would it be backwards?
how about 1.2.1 to 1.3.1?
0
 
jwcorbettAuthor Commented:
Basically, I think it comes down to evaluating the digits between the dots.

would 1.85 to 2.01 be a skip?
Yes, this is a skip.  
This scenario (1.X to 2.X), is somwhat hard to handle...for this one the "OK" scenario would be 1.85 to 1.86.

would 1.9 to 1.10 be a skip?  Would it be backwards?
This would be OK, not a skip or backwards.

how about 1.2.1 to 1.3.1
Yes, this would be a skip, 1.2.1 going to 1.2.2 would be OK.





0
 
ozoCommented:
So what is allowed to preceed 2.0?
1.9 is ok, 1.85 is not, what about 1.99 or 1.9.9?
0
 
jwcorbettAuthor Commented:
For the purposes of this script, going to 2.0 from any 1.X would be a skip (1.9 to 2.0 is not OK, 1.9 to 1.10 would be OK).

In practice, if we go to 2.0 from 1.X, it's a new release and would be handled accordingly (baseline would start at 2.X).



0
 
ozoCommented:
#maybe you want something like this.  I'm not sure about the skip condition
#!/usr/bin/perl
$/="File: ";
while( <> ){
    next unless /^before.*revision:\s*([\d.]+).*after.*revision:\s*([\d.]+)/ms;
    $before=eval"v$1";    $after=eval"v$2";
    print /(\S.*)/," backwards \n" if $after lt $before;
    print /(\S.*)/," skip\n" if ord(substr$before,-1)+1 < ord(substr$after,-1)\
;
}
0
 
jwcorbettAuthor Commented:
Initial test show that this will get me going...let me get it implemented into the script before I close out the question.

Thanks Ozo! Once again, it's Ozo nice to have you around!
0
 
ozoCommented:
Or maybe this is better
#!/usr/bin/perl
$/="File: ";
while( <> ){
    next unless /^before\s.*?revision:\s*([\d.]+).*?^after\s.*?revision:\s*([\d.]+)/ms;
    $after=eval"v$2";
    $next=eval"v$1";
    substr($next,-1)=chr(ord(substr$next,-1)+1);
    print /(\S.*)/," backwards\n" if $after lt $next;
    print /(\S.*)/," skip\n" if $next lt $after;
}
0
 
jwcorbettAuthor Commented:
Not really better...it lists files whose revision did not change as going backwards...
0
 
ozoCommented:
#!/usr/bin/perl
$/="File: ";
while( <> ){
    next unless /^before\s.*?revision:\s*([\d.]+).*?^after\s.*?revision:\s*([\d.]+)/ms;
    $after=eval"v$2";
    $before=eval"v$1";
    $next=$before;
    substr($next,-1)=chr(ord(substr$next,-1)+1);
    print /(\S.*)/," backwards\n" if $after lt $before;
    print /(\S.*)/," skip\n" if $next lt $after;
}
0
 
jwcorbettAuthor Commented:
That's better...what do you see as the primary differences between your 1st script and the last one?
0
 
jwcorbettAuthor Commented:
Ozo,

How can I get "print /(\S.*)/" into a variable?
If the revision does skip or goes backwards, I'd like to take some action on the filename, but I can't seem to get the filename into a variable...
0
 
ozoCommented:
($variable) = /(\S.*)/;
0
 
jwcorbettAuthor Commented:
That's what I thought too, but when I do that, my variable is equal to 1...

I changed the syntax a bit from the original, this what I'm using:
        if ( "$next" lt "$after" ) {
            print /(\S.*)/," skipped revisions\n";
            $FILEDREV = /(\S.*)/;
            print "The file is $FILEDREV\n";
        }

When I use a log file that has a skipped revision, the output is:
MMS2/All/versions.properties skipped revisions
The file is 1

0
 
ozoCommented:
($FILEDREV) = /(\S.*)/;
0
 
ozoCommented:
the ( ) puts it in list context
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 10
  • 9
Tackle projects and never again get stuck behind a technical roadblock.
Join Now