|
Question : DOS script to compare date and send notification
|
|
Newbie to NT: I would like to set up a MS DOS script that will check the contents of a TXT file and compare it to today's date. If the dates are different, then send out a email. Is there an easy way to do it without downloading software, i.e. blat? Thank you.
|
|
Answer : DOS script to compare date and send notification
|
|
I don't know about ftping the file to the mail server.
Here's the script to do your processing. You'll have to insert the processing to do the emailing and also change the fileName environment variable to whatever the file is named:
@echo off
setlocal
set fileName=input.txt
call :GETDATEPARTS "%date%"
set compDate=%yy%%mm%%dd%
for /f "tokens=*" %%a in ('type "%fileName%" 2^>NUL') do call :PROCESS "%%a"
goto :EOF
:PROCESS
set _w=%~1
call :MONTH2NUM %_w:~3,3%
if /i not "%compDate%"=="20%_w:~7,2%%mm%%_w:~0,2%" goto :EOF
REM ** Do whatever you want to do
goto :EOF
:GETDATEPARTS
set dt=%~1 set tok=1-3
if "%dt:~0,1%" GTR "9" set tok=2-4
set yyyy=
for /f "tokens=%tok% delims=.:/-, " %%a in ('echo %~1') do ( for /f "skip=1 tokens=2-4 delims=/-,()." %%x in ('echo.^|date') do set %%x=%%a&set %%y=%%b&set %%z=%%c )
if not "%yyyy%"=="" set yy=%yyyy%
if 1%yy% LSS 1000 (if %yy% LSS 70 (set yy=20%yy%) else (set yy=19%yy%)) if 1%mm% LSS 100 set mm=0%mm% if 1%dd% LSS 100 set dd=0%dd%
goto :EOF
:MONTH2NUM
if /i "%~1"=="Jan" set mm=01&goto :EOF if /i "%~1"=="Feb" set mm=02&goto :EOF if /i "%~1"=="Mar" set mm=03&goto :EOF if /i "%~1"=="Apr" set mm=04&goto :EOF if /i "%~1"=="May" set mm=05&goto :EOF if /i "%~1"=="Jun" set mm=06&goto :EOF if /i "%~1"=="Jul" set mm=07&goto :EOF if /i "%~1"=="Aug" set mm=08&goto :EOF if /i "%~1"=="Sep" set mm=09&goto :EOF if /i "%~1"=="Oct" set mm=10&goto :EOF if /i "%~1"=="Nov" set mm=11&goto :EOF if /i "%~1"=="Jan" set mm=12&goto :EOF
echo Invalid month: %~1 detected in MONTH2NUM
|
|
|
|