How to implement batch bat to determine whether a file has been updated in the last 5 minutes
This article mainly introduces "how to implement the code of batch bat to judge whether a file has been updated in the last 5 minutes". In daily operation, it is believed that many people have doubts about how to implement batch bat to judge whether a file has been updated in the last 5 minutes. The editor consulted all kinds of materials and sorted out simple and useful methods of operation. I hope it will be helpful to answer the question of "how to implement batch bat to determine whether a file has been updated in the last 5 minutes"! Next, please follow the editor to study!
Background description of the problem:
The test program checks the time in a X.log text, such as 2008-11-1 12:00:00, because the log will be refreshed every 3 minutes, so the time will change. Now my idea is to compare the latest time caught by the program with the system time. If it takes more than 5 minutes, it means that the log of the system has not been generated (the system is dead), and then confirmed that it is dead. In a DB connected to Oracle, insert into the data of some fields into a table that is used to send alarm mail. I wonder if the bat document can be implemented.
The code is as follows:
@ echo off
Set SrcFile=D:/a.txt
For / f "skip=5 tokens=1-2 delims=" an in ('dir / tw "SrcFile%"') do (
Set "FileDay=%%a" b "
Goto: compare
)
: compare
Call: DateToMins% FileDay:~0,4%% FileDay:~5,2%% FileDay:~8,2%% FileDay:~11,2%% FileDay:~14,3% mFileDay
Call: DateToMins% date:~4,4%% date:~9,2%% date:~12,2%% time:~0,2%% time:~3,2% mToday
Set / a mMinus=mToday-mFileDay
If% mMinus% gtr 5 (
Echo "The system is down"
) else (
Echo "The system is running"
)
Pause
Goto: eof
DateToMins% yy%% mm%% dd%% hh%% mm% result
Setlocal ENABLEEXTENSIONS
Set yy=%1&set mm=%2&set dd=%3&set hh=%4&set nn=%5
If 1% y% LSS 200 if 1% y% LSS 170 (set yy=20%yy%) else (set yy=19%yy%)
Set / a dd=100%dd%%0,mm=100%mm%%0
Set / a zaqiang 14qmm penny pencils 12department yay yyies 4800liz repertoire mlbs 12m squares 3jacks 153mm penny 2
Set / a j=j/5+dd+y*365+y/4-y/100+y/400-2472633
If 1% hh% LSS 20 set hh=0%hh%
If {% nn:~2,1%} EQU {p} if "% hh%" NEQ "12" set hh=1%hh%&set/a hh-=88
If {% nn:~2,1%} EQU {a} if "% hh%" EQU "12" set hh=00
If {% nn:~2,1%} GEQ {a} set nn=%nn:~0,2%
Set / a hh=100%hh%%0,nn=100%nn%%0,j=j*1440+hh*60+nn
Endlocal&set% 6=%j%&goto: EOF
At this point, the study on "how to implement batch bat to determine whether a file has been updated in the last 5 minutes" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!