Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2012
    Posts
    1

    Parse Log File Perl

    I am having trouble creating a perl file that will search for a string in a file and then copy the next few lines (not always the same number of lines) and write to a file.

    The log file looks like this:

    Code:
    00:00:07,796 ERROR [AttributeSyncCallback] Changed user cannot be mapped during attribute sync: 64927595d979914f95364d249ed340a1  Channel: channel16
    com.pingidentity.provisioner.mapping.MappingException: ; Mappings errors: Email - [Required but null], Username - [Required but null]
    	at com.pingidentity.provisioner.mapping.IdentityMapper.map(IdentityMapper.java:229)
    	at com.pingidentity.provisioner.channel.AttributeSyncCallback.process(AttributeSyncCallback.java:47)
    	at com.pingidentity.provisioner.directory.spring.UsnChangedUsersCallbackHandler.handleNameClassPair(UsnChangedUsersCallbackHandler.java:51)
    	at com.pingidentity.provisioner.directory.spring.PagingLdapTemplate$CountingNameClassPairCallbackHandler.handleNameClassPair(PagingLdapTemplate.java:318)
    	at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:297)
    	at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:237)
    	at com.pingidentity.provisioner.directory.spring.PagingLdapTemplate.simplePagedSearch(PagingLdapTemplate.java:218)
    	at com.pingidentity.provisioner.directory.spring.PagingLdapTemplate.pagedSearch(PagingLdapTemplate.java:192)
    	at com.pingidentity.provisioner.directory.spring.UsnChangedUsersAlgorithm.process(UsnChangedUsersAlgorithm.java:100)
    	at com.pingidentity.provisioner.directory.spring.SpringLdapDirectoryDriver.processChangedUsers(SpringLdapDirectoryDriver.java:268)
    	at com.pingidentity.provisioner.channel.GenericUserProvisioningChannel.collectAttributeSyncEvents(GenericUserProvisioningChannel.java:510)
    	at com.pingidentity.provisioner.channel.GenericUserProvisioningChannel****n(GenericUserProvisioningChannel.java:252)
    	at com.pingidentity.provisioner.channel****nner.SequentialChannelRunner****n(SequentialChannelRunner.java:136)
    	at java.util.TimerThread.mainLoop(Timer.java:512)
    	at java.util.TimerThread****n(Timer.java:462)
    00:00:22,054 ERROR [AttributeSyncCallback] Changed user cannot be mapped during attribute sync: f9a91aecb8f8c542b4438a3d86c38e45  Channel: channel16
    com.pingidentity.provisioner.mapping.MappingException: ; Mappings errors: Email - [Required but null], Username - [Required but null]
    	at com.pingidentity.provisioner.mapping.IdentityMapper.map(IdentityMapper.java:229)
    	at com.pingidentity.provisioner.channel.AttributeSyncCallback.process(AttributeSyncCallback.java:47)
    	at com.pingidentity.provisioner.directory.spring.UsnChangedUsersCallbackHandler.handleNameClassPair(UsnChangedUsersCallbackHandler.java:51)
    	at com.pingidentity.provisioner.directory.spring.PagingLdapTemplate$CountingNameClassPairCallbackHandler.handleNameClassPair(PagingLdapTemplate.java:318)
    	at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:297)
    	at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:237)
    	at com.pingidentity.provisioner.directory.spring.PagingLdapTemplate.simplePagedSearch(PagingLdapTemplate.java:218)
    	at com.pingidentity.provisioner.directory.spring.PagingLdapTemplate.pagedSearch(PagingLdapTemplate.java:192)
    	at com.pingidentity.provisioner.directory.spring.UsnChangedUsersAlgorithm.process(UsnChangedUsersAlgorithm.java:100)
    	at com.pingidentity.provisioner.directory.spring.SpringLdapDirectoryDriver.processChangedUsers(SpringLdapDirectoryDriver.java:268)
    	at com.pingidentity.provisioner.channel.GenericUserProvisioningChannel.collectAttributeSyncEvents(GenericUserProvisioningChannel.java:510)
    	at com.pingidentity.provisioner.channel.GenericUserProvisioningChannel****n(GenericUserProvisioningChannel.java:252)
    	at com.pingidentity.provisioner.channel****nner.SequentialChannelRunner****n(SequentialChannelRunner.java:136)
    	at java.util.TimerThread.mainLoop(Timer.java:512)
    	at java.util.TimerThread****n(Timer.java:462)

    And what i want to do is search for
    Code:
    AttributeSyncCallback
    when found copy up to the next line that has the same string
    Code:
    AttributeSyncCallback
    in it and write to file.

    You can see in this example that the work AttributeSyncCallback occurs only twice and are the same length, this is a coincidence and will not always be the same.

    Can anyone help?

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    14,971
    Code:
    p                       { print }
    /AttributeSyncCallback/ { p = !p; if (p) print}
    This is a short AWK script that will do what you want.

    -PatP
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

  3. #3
    Join Date
    Mar 2012
    Posts
    12
    Quote Originally Posted by MMKD View Post
    I am having trouble creating a perl file that will search for a string in a file and then copy the next few lines (not always the same number of lines) and write to a file.

    The log file looks like this:
    [... deleted ...]

    And what i want to do is search for
    Code:
    AttributeSyncCallback
    when found copy up to the next line that has the same string
    Code:
    AttributeSyncCallback
    in it and write to file.
    Do you want to copy it up to line #4 (which the next occurrence), or up to line #18 (which is the end of the error block)?

    You can see in this example that the work AttributeSyncCallback occurs only twice and are the same length, this is a coincidence and will not always be the same.

    Can anyone help?
    The words occur 6 times on 4 lines: 1, 4, 18, and 21. If you want to grab the entire error block, try something like this:

    perl -ne 'print if / ERROR \[your-string\] / ... / ERROR \[/'

    However, this won't grab the 2nd block if the same error string occurs in consecutive blocks, as it did in your input sample. For this, you'll need a more complicated script.
    .

  4. #4
    Join Date
    Jul 2012
    Posts
    1

    Any updates

    I know this is an old thread but has anyone found a solution to this?

  5. #5
    Join Date
    Mar 2012
    Posts
    12
    Quote Originally Posted by doug4knfpu View Post
    I know this is an old thread but has anyone found a solution to this?
    The original poster never clarified what the needs are for the task, so it's hard to say if this question was answered or not. In my email of 3/30/2012, I asked for clarification of what the poster wanted, but never received a reply.

    If you have a similar question, I'd be glad to answer it. You might try Pat Phelan's awk solution on your input file and let us know if it fills the bill.

    Eric

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •