Page 1 of 1

looped reporting

Posted: 18 Mar 2009 04:18
by mikehirst
Here's something I've been playing round with for the past few days. I'm running several processes which I need to monitor. I've been experimenting with running continuous loops which test for certain conditions and report status.

For example the script below tests for the existance of one or more text files. If the files exist a list is output.

Code: Select all

@echo off

:loop
cls
echo.
if exist *.txt (
call:found
) else (
echo text files not found
)
wait 5
goto:loop

:found
echo text files found
echo.
dir /b *.txt
goto:eof


This is a simplified version of what I am doing. I'm actually reading text from log files and reporting changes in temperature, ink levels and the progress of external processes.

I'd be interested to compare notes with other dos users who have written similar batch files.

Posted: 18 Mar 2009 08:17
by RElliott63
I had to do this when we were updating registers. Here's a couple of the functions I setup to do this:

Kick off a background job (aka the START command below) without waiting for it to complete. This way it runs on the command line and all the store personnel saw was a "DO NOT TOUCH" screen. But, it gave messages across the bottom as to the current status.

The "submitted" job would update the "CurrentJob" file as it looped through registers and servers.

The Store Manager would just see that it's still working (the 5 second updates with a Begin/Current Timestamp) and what job it was performing in the MSG area.

Maybe this is somewhat close to what you were discussing ...

-Rick


Code: Select all


 SETLOCAL ENABLEEXTENSIONS
 SETLOCAL ENABLEDELAYEDEXPANSION
 Echo Current Job : Initializing Secure Delete > \CurrentJob

 Call :InitJob

 :: Wait until we have the OK from Corporate
 Call :CheckForFlag
 If /I [!Error!] NEQ [None] (
    Call :DisplayError
    Goto Exit
 ) 

 Start "Processing Secure Delete" /D\ /I /MIN /HIGH SecDel.bat "%Log%"

:: Keep looping until .bat script finishes
 :StillDeleting
 Call :GetCurrentJob
 If NOT Exist \SecDel.Finished (
    Call :WaitForCorporate "!CJob!"
    Sleep 5
    Goto StillDeleting
 )


:: =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
:: Check for Response from Corporate
:: =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 :CheckForFlag
 
 Set "StartWait=%Time%"
 Echo Current Job : Waiting on Corporate Response > \CurrentJob
 
 :KeepChecking
 If NOT Exist \SecDel.* (
 
    Call :GetCurrentJob
    Call :WaitForCorporate "!CJob!"
    Sleep 5
   
    Goto KeepChecking
 )

 If Exist \SecDel.ABORT (
    Call :LogMsg M "Abort Flag was found!"
    Ren SecDel.ABORT SecDel.Abort.%tHHMMSS% > Nul
    Set "Error=Secure Delete Job was Aborted by Corporate!"
    Goto Aborting
 )
 If Exist \SecDel.GO (
    Call :LogMsg M "Go Flag was found!"
    Ren \SecDel.Go SecDel.Go.%tHHMMSS%      > Nul
 )
 
:Aborting
 Set "EndWait=%Time%"
 Cls
 
 Call :LogMsg M "Wait began at %StartWait%"
 Call :LogMsg M "Wait ended at %EndWait%"
 
GOTO:EOF


:: =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
:: Wait For Corporate - Waiting on Approval from Corporate
:: =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 :WaitForCorporate

 Cls
 Echo * =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 Echo *                  ********** W A R N I N G **********
 Echo * =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 Echo * This system is being updated by Corporate!!!!
 Echo *
 Echo *
 Echo *                   DDDD     OOO          NN  N    OOO     TTTTT
 Echo *                   D   D   O   O         N N N   O   O      T
 Echo *                   D   D   O   O         N  NN   O   O      T
 Echo *                   DDDD     OOO          N   N    OOO       T
 Echo *
 Echo *
 Echo *                     TTTTT    OOO    U   U    CCCC   H   H
 Echo *                       T     O   O   U   U   C       HHHHH
 Echo *                       T     O   O   U   U   C       H   H
 Echo *                       T      OOO     UUU     CCCC   H   H
 Echo *
 Echo *
 Echo * =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 Echo *  This screen will update as it processes.  DO NOT use the Registers or     
 Echo *  Server during this process.  Call the HELPDESK before you touch ANYTHING!
 Echo * =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 Echo * ==: %~1
 Echo * =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 Echo Began: %StartWait%                                  Last Check: %Time%           

Goto:EOF

:: =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
:: Get the Current Job Status
:: =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 :GetCurrentJob
 
 If Exist \CurrentJob (
    Find "Current Job" \CurrentJob > %Temp%\CJob
    For /F "tokens=1* delims=" %%C in (%Temp%\CJob) Do (
       Set "CJob=%%C"
    )
    Erase %Temp%\CJob 1>Nul 2>Nul
 )

Goto:EOF



Posted: 18 Mar 2009 08:59
by mikehirst
Rick.

Thanks for your prompt response. Yours is a much better laid out version of what I was trying to do. I like way you use the full screen.

I appreciate your input.

Best Wishes

Mike