script

BASH redirection reference

Posted on Updated on

#!/bin/bash

# redirect stdout to file
cmd > file
# redirect stderr to file
cmd 2> file
# redirect both stderr and stdout to file
cmd >& file
# pipe cmd1's stdout to cmd2's stdin
cmd1 | cmd2
# pipe cmd1's stdout and stderr to cmd2's stdin
cmd1 2>&1 | cmd2
# print cmd1's stdout to screen and also write to file
cmd1 | tee file
# print stdout and stderr to screen while writing to file
cmd1 2>&1 | tee file
Advertisements

Script for emailing DFS Replication Health Reports

Posted on Updated on

DFS replication is a great way to synchronize data for DR purposes, but there is no built in scheduled reporting mechanism.  Well here is a script I wrote that runs the dfrsadmin reports and attaches each report, as well as sends links to each report for review.  Very helpful considering I was logging in each day and running commands to check the backlog.  Now, I can just open these reports every day and all the information is right there.  Once the script is there, simply create a scheduled task to run this script at whatever time interval is needed to receive these reports.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

@echo off

set CURRDATE=%TEMP%\CURRDATE.TMP
set CURRTIME=%TEMP%\CURRTIME.TMP
set REPORTS=\\*******\*******
set FROM="DFS Replication <******@*******>"
set TO="******* <*******@*******>"

DATE /T > %CURRDATE%
TIME /T > %CURRTIME%

:: This cleans up old reports to conserve space.
FORFILES /p E:\****************** /m *.* /d -30 /c "cmd /c del @FILE"

:: adds the date/time to the report name and to the title of the email
for /F "tokens=1,2,3,4 delims=/, " %%i in (%CURRDATE%) Do SET DDMMYYYY=%%j-%%k-%%l
for /F "tokens=1,2,3 delims=:, " %%i in (%CURRTIME%) Do Set HHMM=%%i%%j%%k

set RG_Report=%REPORTS%\folder1-%DDMMYYYY%-%HHMM%.html

:: define the report options as specified in the dfrsadmin.exe utility
dfsradmin health new /rgname:folder1 /refmemname:server1 /ReportName:%RG_Report% /fscount:true

:: overwrite the report file names to temp
echo folder1 %RG_Report% > %TEMP%\healthMessageBodyRG.txt

:: include the links to the reports up in the body of the message
echo folder1 %RG_Report% > %TEMP%\healthMessageBody.txt

:: format the individual report to be sent as an attachment
for /F "tokens=2 delims= " %%i in (%TEMP%\healthMessageBodyRG1.txt) Do SET FILESRG=%%i

:: email the links as well as the attachments using sendEmail.exe
sendEmail.exe -f %FROM% -t %TO% -u "DFS Replication Health Reports %DDMMYYYY%" -o message-file=%TEMP%\healthMessageBody.txt -s smtpserver.domain.com -a %FILESRG%