Query a log for error in the last 30 minutes

Hi,
I'm trying to parse a plain text log file for errors and then send an email.
The error code I'm looking for is "297 WARN". I only want to check the last 30 minutes of the log file and will run the PowerShell parsing script every 30 mins.
I'm stuck at the bit where I make PowerShell only scan back the last 30 minutes. When I run the script below without the substring it works but parses the whole log file. How can I get it to stop parsing at the 30 minute timeline??
The script I have so far is as follows:
# Set Time Variable
$Date = Get-Date
$dateStr = $Date.AddMinutes(-30).ToString("yyyy-MM-dd HH:mm")
#Set log file location
$File = "C:\log.txt"
# Get content from log to time
$logfile = Get-Content $File | ? { $_.substring(0,11) -ge $datestr }  | Select-String "297 WARN"
if ($logfile) {
  foreach ($line in $logfile){
    Write-Host $line
<# 
  ###Send Email
    $mailMessage = New-Object System.Net.Mail.MailMessage
    $mailMessage.IsBodyHTML = $true
    $mailMessage.From = "$email"
    $mailMessage.Subject = "Log Checked with Error"
    $SMTPServer = "smtp.mailserver.com"
    $SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 25)
    $mailMessage.To.Add("[email protected]")
    $mailMessage.Body = $line
    $SMTPClient.Send($mailMessage)
    $LogAttachment.Dispose()
#>
  } else {
   Write-Host "$($Date): no errors"
The log file has the following format (two lines shown):
2015-01-21 16:58:43,148 INFO  [ActivityInstanceBean] (CarnotApplicationQueueListenerContainer-1) State change for Activity instance 'Warten',  oid: 1853 (process instance = 259) (model oid = 2, version = 4.1.6, revision = 0): Created-->Hibernated.
2015-01-21 16:59:00,297 WARN  [SQL] (CarnotDaemonQueueListenerContainer-4) Failed query: SELECT oid, type, code, stamp, state, partition FROM dbo.daemon_log WHERE (dbo.daemon_log.type = 'event.daemon' AND dbo.daemon_log.code = 0 AND dbo.daemon_log.partition
= 1)
Thanks very much fro any help!

Hi Dforager,
To parse the log file basd on the datatime, please refer to the script below to start:
$file = "e:\log.txt"
$Date = Get-Date
Get-Content $file |
Select-String "297 WARN" -SimpleMatch |
select -expand line |
foreach {
if($_ -match '(.+),297 WARN\s(.+)'){
new-object psobject -Property @{
Date = [datetime]$matches[1]
Error = $matches[2]}|
where {$_.Date -gt $Date.AddMinutes(-30)}
If there is anything else regarding this script, please feel free to post back.
Best Regards,
Anna Wang
Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Support, contact [email protected]

Similar Messages

  • When trying to create connection using Contribute 6.5, get error message "Unknown error.  Please see the log for detail."  The log says "Network connection timed out."  What do I do now?

    Have been using Contribute 6.5, and earlier versions, for years with Hostway without any problems.  All of a sudden I cannot create a connection to our website.  Tried to chat with Adobe a twice now and got no help.  Yesterday they started a chat with me, then ended the session without any communication!  My problem has been going on for several weeks now.  I uninstalled Contribute, downloaded and installed again, but it did not help.  Hostway had me connect with Zilla and everything worked fine.  So, they say the problem is with Adobe.    The last attempt ended with "Unknown error. Please see the log for detail."  The log says "Network operation timed out."  Does anyone have any suggestions?

    Hi There,
    Can you please try using any other Internet connection outside your company's network and see if it is working? Alternatively, Can you please try the below settings from the Advanced... Menu while creating the connection using FTP details and try to create the connection again:
    Regards,
    Mayank

  • Oracle 11G/ MV log is newer than the last full refresh

    MV log is newer than the last full refresh / MV-Log ist neuer als letzter vollständiger Refresh
    Oracle 11G
    We access from two data banks about MATERIALIZED VIEWs a big master table.
    The second data bank is new created. A Complete-Refresh lasts > one hour.
    Then never takes place fast-refresh because the MV log on the master db
    does not reproach with the data long enough. What can we do? Can one
    increase the hold duration of the data in the MV LOG?
    Thanks!
    Edited by: 952865 on 15.08.2012 02:27
    Edited by: 952865 on 15.08.2012 02:28

    What do you get with the following query on the side of your master table?
    with
    sg as
    (select segment_name,owner, bytes
       from sys.dba_segments
      where segment_name like 'MLOG$%'),
    tb as
    (select owner, object_name, object_type, created, last_ddl_time
       from sys.dba_objects where object_type = 'TABLE')
    select
      bm.owner bm_owner,
      ml.log_owner ml_owner,
      bm.master bm_table,
      ml.master ml_table,
      ml.log_table log_table,
      sg.bytes log_size,
      tb.created log_created,
      tb.last_ddl_time log_modified,
      bm.mview_id bm_id,
      rm.mview_id rm_id,
      rm.owner s_owner,
      rm.name s_table,
      rm.mview_site s_site,
      rm.can_use_log,
      rm.version,
      ml.rowids ml_rwid,
      ml.primary_key ml_pk,
      rm.refresh_method rm_meth,
      ml.sequence ml_seq,
      ml.include_new_values ml_new,
      bm.mview_last_refresh_time
    from            sys.dba_registered_mviews rm
    full outer join sys.dba_base_table_mviews bm
      on bm.mview_id = rm.mview_id
    full outer join sys.dba_mview_logs ml
      on bm.master = ml.master and bm.owner = ml.log_owner
    full outer join sg
      on ml.log_table = sg.segment_name and ml.log_owner = sg.owner
    left outer join tb
      on tb.owner = sg.owner and tb.object_name = sg.segment_name
    where
         bm.master is null
      or bm.master = :mastertable
      or ml.master is null
      or ml.master = :mastertable
    order by 1,2;For :mastertable you have to insert the name of the table, where you created the MV LOG on.

  • Assigned MP errors in the last?

    Hi, I foung this assigned MP errors in the last in many locationservice logs from one site for me it look like the client have problem to communicate with MP
    SCCM client LocationService.log
    Executing Task LSSiteRoleCycleTask LocationServices 2013-04-12 12:14:21 3496 (0x0DA8)
    1 assigned MP errors in the last 10 minutes, threshold is 5. LocationServices 2013-04-12 12:14:21 3496 (0x0DA8)
    Executing Task LSSiteRoleCycleTask LocationServices 2013-04-12 12:14:21 4588 (0x11EC)
    2 assigned MP errors in the last 10 minutes, threshold is 5. LocationServices 2013-04-12 12:14:21 4588 (0x11EC)
    Current AD site of machine is Tingsryd LocationServices 2013-04-12 12:14:44 3496 (0x0DA8)
    Executing Task LSSiteRoleCycleTask LocationServices 2013-04-12 12:16:21 3332 (0x0D04)
    3 assigned MP errors in the last 10 minutes, threshold is 5. LocationServices 2013-04-12 12:16:21 3332 (0x0D04)
    Executing Task LSSiteRoleCycleTask LocationServices 2013-04-12 12:18:27 4588 (0x11EC)
    4 assigned MP errors in the last 10 minutes, threshold is 5. LocationServices 2013-04-12 12:18:27 4588 (0x11EC)
    Executing Task LSSiteRoleCycleTask LocationServices 2013-04-12 12:18:27 4588 (0x11EC)
    Assigned MP error threshold reached, moving to next MP. LocationServices 2013-04-12 12:18:27 4588 (0x11EC)
    Executing Task LSSiteRoleCycleTask LocationServices 2013-04-12 12:20:27 6716 (0x1A3C)
    Executing Task LSSiteRoleCycleTask LocationServices 2013-04-12 12:20:27 4316 (0x10DC)
    1 assigned MP errors in the last 10 minutes, threshold is 5. LocationServices 2013-04-12 12:20:27 6716 (0x1A3C)
    2 assigned MP errors in the last 10 minutes, threshold is 5. LocationServices 2013-04-12 12:20:27 4316 (0x10DC)
    Executing Task LSSiteRoleCycleTask LocationServices 2013-04-12 12:23:27 8120 (0x1FB8)
    3 assigned MP errors in the last 10 minutes, threshold is 5. LocationServices 2013-04-12 12:23:27 8120 (0x1FB8)
    Executing Task LSSiteRoleCycleTask LocationServices 2013-04-12 12:24:27 1508 (0x05E4)
    4 assigned MP errors in the last 10 minutes, threshold is 5. LocationServices 2013-04-12 12:24:27 1508 (0x05E4)
    Current AD site of machine is Tingsryd LocationServices 2013-04-12 12:29:59 6792 (0x1A88)
    Attempting to retrieve lookup MP(s) from AD LocationServices 2013-04-12 12:29:59 6976 (0x1B40)
    /SaiTech

    1 assigned MP errors in the last 10 minutes, threshold is 5. LocationServices 2013-04-12 12:14:21 3496 (0x0DA8)
    I've seen those messages on fully functional clients, so it is most likely nothing to worry about.
    Torsten Meringer | http://www.mssccmfaq.de
    http://social.technet.microsoft.com/Forums/en-US/45a7d465-dc38-4168-bfb4-bdc8f49f17aa/configuration-manager-properties-there-are-only-2-actions?forum=configmanagergeneral
    Hi Torsten,
    I'm the guy who posted the above question. I have checked recommended log files and mpcontrol.log
    I saw some errors but I really dont know how to solve. I have managed te server for a long time and just got this issue recently.
    Le Nhut Minh PwC Vietname Limited.

  • Im trying to burn a lp from itunes, but it keeps cancelling at the last minute and saying error 4000

    im trying to burn a lp from itunes, but it keeps cancelling at the last minute and saying error 4000

    Hi there,
    I would recommend taking a look at the troubleshooting steps found in the article below.
    Can't burn a CD in iTunes for Windows
    http://support.apple.com/kb/TS1436
    -Griff W.

  • IDVD working till I installed 2TB ED. Keep getting message"There was an internal iDVD error during the last action. This is not a movie." Any help is appreciated.

    iMovie message "There was an internal iDVD error during the last action. This is not a movie." comes up after trying to create a movie to burn to iDVD. Recently added a 2TB external drive to free up memory from HD. iDVD was working fine till the ED was added. Can't burn DVDs anymore. Any suggestions on how to fix the problem?

    What  folders did you move to the EHD? Any of the basic Home folders?  What format is the EHD?  It should be OS X Extended (journaled).  Do you have any files that iDVD uses on the EHS, i.e. project files, media files?
    OT

  • I've got a problem:  if i want to back up my device manual (the same thing if it should does automaticly by charging) there's an error called: "the last backup couldn't be constructed"(don't know if it's right written, i'm german).Does sb. know what do?

    i've got a problem:  if i want to back up my device manual (the same thing if it should does automaticly by charging) there's an error called: "the last backup couldn't be constructed"(don't know if it's right written, i'm german).Does sb. know what to do? Help would be nice!!
    Henrik

    Sorry its Thanksgiving holiday here, here is a picture of the hard drive.
    After doing this, try the other suggestions if needed. then let us know!
    S70-ABT2N22 Windows 7 Pro & 8.1Pro, C55-A5180 Windows 8.1****Click on White “Kudos” STAR to say thanks!****
    Attachments:
    toshiba hard drive.jpg ‏14 KB

  • HT4859 Can't backup my Iphone to Icloud. Keep getting error message, "The last backup could not be completed".  Any suggestions?

    I keep getting error message, "The last backup could not be completed" when trying to backup Iphone to Icloud.  I have plenty of storage space.  Phone is plugged in, connected to WI-FI & is locked.  Does anyone know what is wrong?  Thanks

    HELP!  Is there anyone out there who knows how I can fix this????
    Thanks!

  • Pre-order contents may differ again at the last minute

    It has happened again!
    It happened with the new Portishead album Third. At the last minute they put a note on the page saying that the contents are subject to change without notice and the final product may differ. Then one of the bonus live tracks got removed!
    I have the new Verve alb Forth on pre-ord and i am currently awaiting for it to download, but it just came up with the same warning, so I am thinking that one of the two free live bonus tracks are going to be taken off some reason as well.
    If this happens, then I am sorry but it is not on. It's not a big deal, but it's a deal. If you go to a shop and pay for a bag of apples 1 day before you get them, and they say that you will get two extra apples for paying up front, then you should get two extra apples, or else a free bag of apples the next day.

    Actually, just to correct myself. Neither album gave away the bonus tracks for pre-ordering, but certainly they should definately be included if you preordered.

  • HT203167 why has the last minute 20 seconds suddenly disappeared from a song?

    why has the last minute 20 seconds suddenly disappeared from a song?

    Welcome to the Apple Community.
    Try deleting the problematic file (electing to remove original file if/when prompted) and then re-downloading the file from the iTunes store.
    You can re-download content purchased from the iTunes store (availability varies depending on location) using the purchased option from the Quick Links section in the top right corner of the iTunes homepage in your iTunes application on your computer.
    You can re-download content purchased from the iTunes store (availability varies depending on location) using the purchased option at the bottom of the screen of the iTunes app (or video app) on your iOS device.
    If the problem re-occurs, select the content which is causing a problem and use the 'Report a problem' button in Your Purchase History using your computer.

  • How could I re-open my mail box with error message :The last time you opened Mail, it unexpectedly quit while reopening windows. Do you want to try to reopen its windows again?

    How could I re-open my mail box, as an error message blocked "The last time you opened Mail, it unexpectedly quit while reopening windows. Do you want to try to reopen its windows again?" Even I entered re-open, the airbook does not response but prompt the same error message again.

    Please follow these directions to delete the Mail "sandbox" folders. In OS X 10.9 there are two sandboxes, while in 10.8 there is only one. If you're running a version older than 10.8, this comment isn't applicable.
    Back up all data.
    Triple-click anywhere in the line below on this page to select it:
    ~/Library/Containers/com.apple.mail
    Right-click or control-click the highlighted line and select
    Services ▹ Reveal
    from the contextual menu.* A Finder window should open with a folder named "com.apple.mail" selected. If it does, move the selected folder — not just its contents — to the Desktop. Leave the Finder window open for now.
    Log out and log back in. Launch Mail and test. If the problem is resolved, you may have to recreate some of your Mail settings. You can then delete the folder you moved and close the Finder window. If you still have the problem, quit Mail again and put the folder back where it was, overwriting the one that may have been created in its place. Repeat with this line:
    ~/Library/Containers/com.apple.MailServiceAgent
    Caution: If you change any of the contents of the sandbox, but leave the folder itself in place, Mail may crash or not launch at all. Deleting the whole sandbox will cause it to be rebuilt automatically.
    *If you don't see the contextual menu item, copy the selected text to the Clipboard by pressing the key combination  command-C. In the Finder, select
    Go ▹ Go to Folder...
    from the menu bar, paste into the box that opens (command-V). You won't see what you pasted because a line break is included. Press return.

  • Error starting the last available version of PC su...

    After installing when running pc suite I get this error
    The application failed to initialize properly (0x0150002). Click OK to terminate the aplication.
    I have never had this erro before.
    I have W xp sp2

    After sometime I discovered sme more information about this issue. After installing the lst PC Suite version I get an application error.
    nspecting Windows event log I have this four messages related with this:
    1) Dependent Assembly Microsoft.VC80.MFC could not be found and Last Error was The referenced assembly is not installed on your system.
    2)Resolve Partial Assembly failed for Microsoft.VC80.MFC.
    Reference error message: The referenced assembly is not installed on your system.
    3) Generate Activation Context failed for C:\Program Files\Nokia\Nokia PC Suite 7\PCSSupportSetup.DLL.
    Reference error message: The operation completed successfully.
    4) Application popup: PCSuite.exe - Application Error : The application failed to initialize properly (0xc0150002). Click on OK to terminate the application.
    Anyone can provide a solution?

  • Simple Query Question - How do I return the Last 3 records of a Table?

    Question.
    For example, I have a table that has 50 records.
    How do I, specify in SQL to only return the last 3 records of the table.
    Select a.* from table a where ????

    I was just trying to show an example to a friend on
    how something like this would work and if it was even possible. But it won't work. Here's a simple example:
    SQL> create table emp
      2  (id)
      3  as
      4  select object_id
      5  from   all_objects
      6  order  by object_id;
    Table created.
    SQL> select *
      2  from  (select rownum rn
      3               ,b.*
      4         from   emp b)
      5  where  rn > ( select (max(rownum) - 3)
      6                from    emp)
      7  ;
            RN         ID
         40830      55891
         40831      55892
         40832      55893So far, so good. These are the "last 3" rows inserted. Now delete a bunch of rows and insert 3 new ones:
    SQL> delete emp where id < 40000;
    33423 rows deleted.
    SQL> commit;
    Commit complete.
    SQL> insert into emp values (60000);
    1 row created.
    SQL> insert into emp values (60001);
    1 row created.
    SQL> insert into emp values (60002);
    1 row created.
    SQL> commit;
    Commit complete.
    SQL> select *
      2  from  (select rownum rn
      3               ,b.*
      4         from   emp b)
      5  where  rn > ( select (max(rownum) - 3)
      6                from    emp)
      7  ;
            RN         ID
          7410      55891
          7411      55892
          7412      55893Here's the problem. Even though the "last 3 rows" are 60000 - 60002, I still get the same ones as the first query.

  • Log-on freezes at the last step

    Hi,
    We use BPC 7.5 NetWeaver version SP08.
    We have noticed that occasionally some of our end users are experiencing the following problem:
    When they try to log on either through the Planning and Consolidation for Office Client or through the Planning and Consolidation Administration Client the log-on process freezes at the last step where the connection bar is shown i.e. after they input their credentials and press Next button.
    It should be stressed that this problem appears occasionally and only on specific end usersu2019 PCs.
    I would very much appreciate any help.
    Thank you in advance,
    Mike

    Hi Roberto,
    Thank you very much for your prompt response the issue seems to be very close to what is described in notes
    ·         1624426
    ·         1664394
    Unfortunately We have tried both notes i.e. our Administrator verified that port is 80 and we have tried to use the ‘DNS-hostname:80’ and the problem still occasionally appears (I stress occasional and from specific end user’s PCs).
    Any other ideas?
    Thank you in advance.
    Kind Regards
    Mike 

  • Jdev10.1.3 - error in the last step of Sample Databound cuecard example

    Hello
    I am trying to execute the last step in Sample Databound cuecard example i,e 'Add a Field for the parameter value'. in the output browser when i am entering the 'sh' in to the input text field and when i click the 'FindContactsByName' button i am not getting the names containig 'sh'in the table component of the same page.
    If any of you are the aware of this error ..Please help me how to overcome this error.
    I appriciate all your time and patience.
    Thanks

    Hello
    I am trying to execute the last step in Sample Databound cuecard example i,e 'Add a Field for the parameter value'. in the output browser when i am entering the 'sh' in to the input text field and when i click the 'FindContactsByName' button i am not getting the names containig 'sh'in the table component of the same page.
    If any of you are the aware of this error ..Please help me how to overcome this error.
    I appriciate all your time and patience.
    Thanks

Maybe you are looking for

  • Lens Profile Support LR5

    Lens profiles not showing up in LR 5. Working on a Mac 10.7.5, Photoshop CS6, and Camera Raw 8.3 installed. In Lightroom 4, my Canon 6D camera was supported, all lens profiles appearing in LR, was able to choose my Tamron 28-200 mm profile for raw im

  • Problem in script format

    hi, i am having problem in script , the problem is s.no|    descriptio                           |   UOM                      |          Qty                   |             Rate           |          AMT            | 01     aaaaaaaaaaaaaaaaaaaaa      

  • Account determination error on Goods Receipts Mov 101

    Hi Gurus Please assist, i am gettitng error message ACCOUNT DETERMINATION for entry RCON KBS 0001 is not possible Regards Palesa

  • Take an approved from Multi Approval process

    Hello! I need take a value (Aprove o reject) for every approver in Multi Approval process, Can anyone help me? This is the code: <set name='approvals.approvers'> <list> <s>ESM3801A</s> <s>ESM3801B</s> </list> </set> <Argument name='style' value='alla

  • No thumbnail/icons for personal pictures in the finder..

    So, I bought an iMac recently and I'm really liking it - but one irritating issue. On my personal pictures (not default pictures like the iChat icons in the same folder, pictures I've saved onto there) in the Pictures folder in the Finder, the pictur