Using a regular expression to look for successful backup in log

This topic contains 6 replies, has 4 voices, and was last updated by Profile photo of Graham Beer Graham Beer 6 months, 2 weeks ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #36503
    Profile photo of Graham Beer
    Graham Beer
    Participant

    Hi,

    I'm writing a backup copy script for SCCM to copy the backup files to another server for redundancy purposes.

    This is the example line:
    Backup completed – Mon Nov 23 22:30:23 2015 $$ This is just to test on the one line, but i will look for the last successful date $a = get-content "E:\SCCM_Backup\AACBackup\smsbkup.log" | where { $_ -like "*Backup completed - Mon Nov 23 22:30:23 2015*" } Create the pattern

    [regex]$pattern = "\$\$< (1[0-2]|0[1-9]|[1-9])-"
    

    Finally select the first line

    $a[0]
    

    This does give me the desired result but doesn't feel right. Can someone point me in the right direction please ?

    #36507
    Profile photo of Chris Bakker
    Chris Bakker
    Participant

    The \$\$ in the regex is searching for $$, and thats not in your backup line.
    So what in the logfile, what are you trying to match?

    #36509
    Profile photo of Graham Beer
    Graham Beer
    Participant

    It keeps purging my string.

    Backup completed – Mon Nov 23 22:30:23 2015 $$ SMS_SITE_BACKUP11-23-2015 22:30:23.907+00thread=8928 (0x22E0)

    I've had to remove < as it removes them.Its an SCCM log file.I just want to extract "Backup completed – Mon Nov 23 22:30:23 2015"

    #36520
    Profile photo of random commandline
    random commandline
    Participant
    (Get-Content .\file.log) -match "(?'line'Backup .* \d{4})" ; $Matches['line']
    # Result: True
    # Backup completed – Mon Nov 23 22:30:23 2015
    
    #36528
    Profile photo of Graham Beer
    Graham Beer
    Participant

    Thanks Random, I shall give it ago. Will it extract just "Backup completed – Mon Nov 23 22:30:23 2015" ?

    #36537
    Profile photo of random commandline
    random commandline
    Participant

    Yes, it should. My previous post displays the results.

    #36540
    Profile photo of Graham Beer
    Graham Beer
    Participant

    Thank you again Random. Could you explain the method you used? Trying to get my head round it. Cheers !

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.