Batch BAT Determines whether a file has been updated in the last 5 minutes by the code _dos/bat

Source: Internet
Author: User
Tags goto system log

Problem Background Description:

The test program looks at the time in a X.log text, similar to the format of 2008-11-1 12:00:00, because the log is refreshed every 3 minutes, so the time will change, and now my idea is to use the program to catch the latest is the maximum time and system time to do, more than 5 minutes, It means that the system log has not been regenerated (the system is dead), and then after confirming that it is dead, in a DB connected to Oracle, insert some field data into a table to send alarm mail. I don't know if the bat document will be implemented.

Copy Code code as follows:

@echo off
Set Srcfile=d:/a.txt
for/f "skip=5 tokens=1-2 delims="%%a in (' Dir/tw "%srcfile%" ') Do (
Set "Fileday=%%a%%b"
Goto:compare
)
: Compare
Call:D atetomins%fileday:~0,4%%fileday:~5,2%%fileday:~8,2%%fileday:~11,2%%fileday:~14,3% MFileDay
Call:D atetomins%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

:D atetomins%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%yy% LSS if 1%yy% LSS 170 (set yy=20%yy%) Else (set yy=19%yy%)
set/a dd=100%dd%%%100,mm=100%mm%%%100
set/a z=14-mm,z/=12,y=yy+4800-z,m=mm+12*z-3,j=153*m+2
set/a j=j/5+dd+y*365+y/4-y/100+y/400-2472633
If 1%hh% LSS set hh=0%hh%
If {%nn:~2,1%} EQU {p} if "%hh%" NEQ "set hh=1%hh%&set/a hh-=88
If {%nn:~2,1%} EQU {A} if "%hh%" EQU "Set hh=00"
If {%nn:~2,1%} GEQ {a} set nn=%nn:~0,2%
set/a Hh=100%hh%%%100,nn=100%nn%%%100,j=j*1440+hh*60+nn
Endlocal&set%6=%j%&goto:eof

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.