Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Team,
I want to monitor a log file of a service.
If service is running normal then this get update in every 15min. So I want to monitor if the log file is getting updated in every 15min or not. If its not updating then it means service is not running. and hence it must send some echo statement.
Could you please help me on this?
I tried " %~tI - expands %I to date/time of file" but this returns the file creation time.
So please suggest me if we have any other way out for this.

First of all your operating system is not DOS as you are talking about services and variable modifiers, I suppose you are running a NT based environment like XP or 2000 where there is no DOS at all.
About your problem you have to parse the output of Dir command with the /TW switch that takes into account the most recent access to write the file. Something as
for /F "tokens=2" %%a in ('dir /TW log.txt') do (
echo Log.txt updated at %%~b)

You COULD do it in DOS:
::==
@echo offif not exist # goto :firstrun
fc log # > nul
if errorlevel 1 echo it's been changed
:firstrun
copy /b log # > nul
=====================================
If at first you don't succeed, you're about average.M2

If you just want to know if a service is running, why not use the actual command that tells you if a service is running?
NET START

thanks.. i think dir /tw option will work..
and i must say .. I dont have full access on the server due to IS rules.
So I can just monitor log files in order to monitor the service is running or not.
I am planing to use /tw option with a find command. I will pass todays date and current hour from date/t and time/t command. will try to search this pattern in find command.could you pls help me in this.

You can nevermind the /TW; it's the default.
=====================================
If at first you don't succeed, you're about average.M2

I want to find this without saving out put of dir to any file.
without creating any few temp file i want to find out this.
could u pls suggest me some solution.

I think klint said it: use the right tool.
=====================================
If at first you don't succeed, you're about average.M2

M2, as I understand it vishu can't use my suggestion because it requires Administrator privilege. On the other hand, he can see the file the service creates, even without Administrator privilege, so he can see whether the service is running or not using this indirect method.
To avoid creating a temporary file, he will have to keep the last checked file timestamp in an environment variable. That's a bit tricky for me right now.

picky, picky, picky
Here's one; no admin, no files
::==
@echo offfor /f "tokens=* delims= " %%a in ('dir/b log') do (
set new=%%~Ta
)if "%old%" neq "%new%" echo changed
set old=%new%
=====================================
If at first you don't succeed, you're about average.M2

M2... thanks a lot. But I think we cant use %%~T option as it returns only file creation date.
so to understand the file modification date i think we have to use some option form DIR command.
But i really dont understand how it will work without creating a a temp file.

LOL Regardless of what anyone 'thinks' it shows last modified date/time.
Try it.
=====================================
If at first you don't succeed, you're about average.M2

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |