08-07-2015 06:34 AM
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?
Solved! Go to Solution.
08-07-2015 07:37 AM
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.
08-07-2015 07:37 AM
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.
08-07-2015 07:46 AM
Convert current time to EPOCH time - you will get a number like this : 1438958258
Then add 86400 (24h) 3 times to the EPOCH value , and convert back to human time. BINGO!
You can use powershell for time conversion.
Get current time in EPOCH format.
Get-Date -UFormat "%s"
https://technet.microsoft.com/en-us/library/hh849887.aspx
https://technet.microsoft.com/en-us/library/ee692801.aspx
08-07-2015 08:52 AM
Ever tried calling PS with one command from within a DOS batch script and passing parameters encapsulated in quotes? :p
It works fine on an interactive CLI "cmd" session.
I can't get it to work from within a DOS batch script. :(
08-07-2015 10:47 AM
Impressive.. Seems like I'm not the only one who attempts this :) :)
08-07-2015 10:47 AM
Two very good choices to choose from.
08-07-2015 10:54 AM
Have you actually tried running the PS command in a DOS/cmd batch script and collecting and processing the output. It doesn't work for me. However, the VBscript method does work for me.
Need help with a scripted 'blat' command? Need help configuring 'blat' so that one does not have to specify a password hard-coded in a script? Need help configuring 'blat' to talk via 'stunnel' to an SSL based SMTP listenner/server?
08-07-2015 11:02 AM
No - I am a unix dude, don't have windows problem :D
08-07-2015 12:11 PM
08-07-2015 12:36 PM
Works flawlessly SDO!! Thanks!
08-07-2015 01:35 PM
No probs. Hope it helped.