cancel
Showing results for 
Search instead for 
Did you mean: 

Schedule Prediction and BLAT

Seth_E
Level 6

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?

1 ACCEPTED SOLUTION

Accepted Solutions

sdo
Moderator
Moderator
Partner    VIP    Certified

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.

View solution in original post

10 REPLIES 10

sdo
Moderator
Moderator
Partner    VIP    Certified

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.

Nicolai
Moderator
Moderator
Partner    VIP   

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

sdo
Moderator
Moderator
Partner    VIP    Certified

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.  :(

Seth_E
Level 6

Impressive.. Seems like I'm not the only one who attempts this :) :)

 

Seth_E
Level 6

Two very good choices to choose from.

sdo
Moderator
Moderator
Partner    VIP    Certified

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?

 

Nicolai
Moderator
Moderator
Partner    VIP   

No - I am a unix dude, don't have windows problem :D

sdo
Moderator
Moderator
Partner    VIP    Certified
One day I hope to be so too. Unix 'frood' level? Maybe not for me. But for you a possibility! Probability?

Seth_E
Level 6

Works flawlessly SDO!! Thanks!

sdo
Moderator
Moderator
Partner    VIP    Certified

No probs.  Hope it helped.