Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Monitoring Time  (Read 2037 times)

0 Members and 1 Guest are viewing this topic.

CameronY

    Topic Starter


    Intermediate

    Monitoring Time
    « on: May 28, 2008, 10:45:45 PM »
    Hello Everyone,

    Has been some months since I was last here, so I hope everyone is doing well.

    Have a query which I've not been able to search for with any success.

    Wish to create a loop that monitors for the existance of a trigger file.
    The loop will run for a period of X minutes and test for the existance if a "trigger" file every five minutes after the initial test.  Monitoring of the "trigger" file would stop at the end of the period (X minutes) or when the "trigger" is found (which ever happens first).

    I'm intending to use the following para's within the script ...
    set MonitorTime=45                      ##- Monitoring period in minutes.
    set MonitorInterval=5                   ##- Monitoring interval in minutes.
    set TStatus=FALSE                       ##- Trigger Status
    I'm not at all conversant with how this might be achieved or how to manipulate time for this purpose.

    If anyone has examples, links or search criteria that I might be able to use, I'd be more than appreciative. 

    Cheers,
    Cameron
    « Last Edit: May 29, 2008, 04:17:00 AM by CameronY »

    Sidewinder



      Guru

      Thanked: 139
    • Experience: Familiar
    • OS: Windows 10
    Re: Monitoring Time
    « Reply #1 on: May 29, 2008, 04:57:36 AM »
    Batch code does not do date and time arithmetic very well. However you can be a bit creative and use the ping instruction to time your intervals (5 min) and use the for instruction to limit the number of intervals (9) to a 45 minute period.

    Something like this framework might help:

    Code: [Select]
    @echo off
    set tstatus=false
    for /l %%i in (1,1,9) do (
    ping -n 300 127.0.0.1 > nul
    if exist trigger.txt ..........
    )

    You'll need to fixup the if statement to do whatever work when the trigger file shows up.

    Good luck. 8)
    The true sign of intelligence is not knowledge but imagination.

    -- Albert Einstein

    CameronY

      Topic Starter


      Intermediate

      Re: Monitoring Time
      « Reply #2 on: May 29, 2008, 05:29:18 AM »
      Hello Sidewinder,

      Many thanks for the reply.
      Have since gathered batch code doesn't do date/time at all well.
      The ping solution is very clever - thanks for sharing.

      If the trigger file comes into play before the 45 minute period complete's, then the tstatus becomes TRUE and I'll break (or is it exit) out of the loop and continue into an IF routine.

      Cheers & again - thanks,
      Cameron