windows - Batch File Date Format not right -


i have following code checks log file specific string, , based on datestamp matching executes tasks.

now code below works great on windows 7 machine date-time format of: yy-mm-dd hh:mm, executing exact same batch file on windows server 2008 date-time format of: yy-mm-dd hh:mm not work - suspect might date-time format... confirm if date-time format used in batch file work yy-dd-mm date format?

also, if date time format in log file differs dat-time format of log file itself? code still work?

for /f "tokens=2" %%a in ('findstr /i /c:"database ok" log.txt') set "success=%%a" %%a in (log.txt) set "filedate=%%~ta" if "%filedate:~0,10%"=="%success%" (     call another.bat ) else (     >>otherlogfile.log echo(%date% %time% database unsuccessful ) 

thank you


update 1:

c:\utilities\filter>for %a in (logfile.txt) set "filedate=%~ta"  c:\utilities\filter>set "filedate=2013-07-31 21:31"  c:\utilities\filter>rem if still not work remove rem next  line can see being compared  c:\utilities\filter>echo.filedate=!filedate:~0,10!]   success=2013/07/ 31] filedate=2013-07-31]   success=2013/07/31]  c:\utilities\filter>pause press key continue . . . 

as can see, dates beign compared never match, since format not correct.

filedate=2013-07-31]   success=2013/07/31] 

what suggest?


update 2:

setlocal enabledelayedexpansion /f "tokens=2" %%a in ('findstr /i /c:"database ok" logfile.txt') set "success=%%a"  set "%success:^/=-%" echo %success% pause %%a in (logfile.txt) set "filedate=%%~ta"  rem if still not work remove rem next line can see being compared echo.filedate=!filedate:~0,10!]   success=%success%]  pause if "!filedate:~0,10!"=="%success%" (     call another.bat ) else (     >>readlogfail.txt echo(%date% %time% database unsuccessful ) 

the first thing notice if want interrogate run time value of filedate in loop need setlocal enabledelayedexpansion , use ! instead of %. happens work on windows 7 because load time value of success , filedate same. try code below. may find there other things wrong... let's first. note success not interrogated within for/if construct, filedate is.

setlocal enabledelayedexpansion /f "tokens=2" %%a in ('findstr /i /c:"database ok" log.txt') set "success=%%a" set success=%success:/=-% %%a in (log.txt) set "filedate=%%~ta" rem if still not work remove rem next line can see being compared echo.filedate=!filedate:~0,10!]   success=%success%] if "!filedate:~0,10!"=="%success%" (     call another.bat ) else (     >>otherlogfile.log echo(%date% %time% database unsuccessful ) 

Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -