check last modified date & time with current date & time and if file is stagnate for more than 10 min take actin in batch

what would be the simplest way in a batch file to check the modified date and time of a specified file and take a specific action if its more than 10 min old?

@echo off
:loop
echo 3
ping -n 2 127.0.0.1>nul
echo 2
ping -n 2 127.0.0.1>nul
echo 1
ping -n 2 127.0.0.1>nul
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX (
echo logfile is not older than 10 min
) || (
echo attempting to restart
net stop log2
net start log2
)
goto loop
LVL 1
csePixelatedAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

oBdACommented:
Since there's no built-in command line tool to compare dates, here's a batch script that creates a VB script on the fly that does the date calculation:
@echo off
setlocal enabledelayedexpansion
set LogFile=D:\Temp\test.log
set MaxAge=1
set Service=log2

set VbsFile=%Temp%\DateDiff.vbs
call :ExportDataSection VBS "%VbsFile%"
:Loop
cscript.exe //nologo "%VbsFile%"
if errorlevel 1 (
	echo [%Time%] File older than %MaxAge% minutes.
	net.exe stop "%Service%"
	net.exe start "%Service%"
) else (
	echo [%Time%] File current.
)
ping.exe -4 -n 21 localhost >NUL
goto Loop

REM ================================================================================
REM Only functions after this line!
REM ================================================================================
goto :eof
:ExportDataSection
REM *** Reads all lines listed in %1 (section) and writes them to %2 (file name).
REM *** Environment variables will be expanded.
set Section=%~1
set FileName=%~2
if exist "%FileName%" del "%FileName%"
for /f "tokens=1 delims=[]" %%a in ('type "%~f0" ^| C:\Windows\system32\find.exe /n "[%Section%]"') do set DataStart=%%a
for /f "skip=%DataStart% delims=" %%a in ('type "%~f0"') do (
	call :Expand Line "%%a"
	if "!Line:~0,1!"=="[" (goto :eof) else (>>"%FileName%" echo !Line!)
)
goto :eof

:Expand
set %1=%~2
goto :eof

REM ================================================================================
REM Only data sections after this line!
REM ================================================================================
[VBS]
Set objFso = CreateObject("Scripting.FileSystemObject")
Set objFile = objFso.getFile("%LogFile%")
If DateDiff("n", objFile.DateLastModified, Now) > %MaxAge% Then
	intErrorLevel = 1
Else
	intErrorLevel = 0
End If
WScript.Quit(intErrorLevel)

Open in new window

0
NVITCommented:
Do you want a pure .bat solution?

How about a command line utility like WasFile, which:
...compares ...time&date of a file with now-n (minutes)
http://www.horstmuc.de/wbat32.htm#wasfile
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
csePixelatedAuthor Commented:
oBdA I appreciate the input, but i really am looking for the simple solution, i wish i could undoo and give you 100 as i really appreciate the script.
0
NVITCommented:
csePixelated,

You can adjust the points. Pick Request Attention at the bottom right of your original post. Submit your reason.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.