Seth_E
10 years agoLevel 6
Schedule Prediction and BLAT
Hi all,
I want to write a simple batch file that blat will use to email me the status of all Full backups that will run in the next three ays.
I was going to use this:
set month=%date:~4,2%
set day=%date:~7,2%
set year=%date:~10,4%
nbpemreq -due -date %month%/%day%/%year% | findstr "FULL" > c:\schedule.txt
than blat c:\schedule.txt.
This works! But, how do I add 3 days to the date? Or, is there a better way to get this info?
An example script with error checking, logging, runs silently, tolerant of path with spaces, tolerant of most folder paths or file names. Just ensure that both script files have the same leading file name part.
e.g. save this to a file named: future-scheds.bat
@echo off setlocal enabledelayedexpansion set z_script_path=%~dp0 set z_script_name=%~n0 set z_file_log=!z_script_path!!z_script_name!.log set z_file_pem=!z_script_path!!z_script_name!.pem set z_file_tmp=!z_script_path!!z_script_name!.tmp set z_file_txt=!z_script_path!!z_script_name!.txt set z_file_vbs=!z_script_path!!z_script_name!.vbs if exist "!z_file_pem!" del "!z_file_pem!" if exist "!z_file_tmp!" del "!z_file_tmp!" if exist "!z_file_txt!" del "!z_file_txt!" call :r_log "" call :r_log "script started..." cscript //nologo "!z_file_vbs!" >"!z_file_tmp!" 2>&1 set z_sts=!errorlevel! if !z_sts!==0 ( call :r_log "call to VBScript success..." ) else ( call :r_log "call to VBScript failed, status `!z_sts!`, script aborting..." goto :end ) for /f "tokens=*" %%a in ('type "!z_file_tmp!"') do (set z_future=%%a) call :r_log "future date is `!z_future!`..." nbpemreq -due -date !z_future! 00:00:00 >"!z_file_pem!" 2>&1 set z_sts=!errorlevel! if !z_sts!==0 ( call :r_log "call to nbpemreq success..." ) else ( if !z_sts!==1 ( call :r_log "call to nbpemreq success, but found nothing due to run..." ) else ( call :r_log "call to nbpemreq failed, status `!z_sts!`, script aborting..." goto :end ) ) findstr /i "due.time ^$ ^- full" "!z_file_pem!" >"!z_file_txt!" 2>&1 set z_sts=!errorlevel! if !z_sts!==0 ( call :r_log "call to findstr success..." ) else ( call :r_log "call to findstr failed, status `!z_sts!`, script aborting..." goto :end ) :end call :r_log "script exiting with status `!z_sts!`..." exit /b !z_sts! :r_log (echo !date! !time:~0,8! %~1)>>"!z_file_log!" goto :eof
...and save this to a file named: future-scheds.vbs
Option Explicit Dim ld_future ld_future = DateAdd( "d", 3, Now() ) WScript.Echo FormatDateTime( ld_future, vbShortDate ) WScript.Quit
HTH.