BAT/CMD scripts are very much helpful to do a monotonous job automatically and sometimes the outputs of the batch script file are very much required. We can generate log file from batch file, but we can’t get the 100% log within batch file, so I was looking for a tool which generate log files from a batch script. After a few search, finally I found a tiny utility called wtee.exe on wintee.
To use it properly, I have created a batch file with which u can execute any batch script, and after executing the batch file it will automatically archive the entire output log, also there is an option to send mail notification with the output file as mail attachment (optional). For sending mail notification I used blat.exe from www.blat.net.
Default settings are follows…
REM Settings Start
::Set Destination, source drive, and restore folder
set LogPath=D:TCleanLog
set LogName=TempCleanLog
set LogExt=.log
set WinTee=wtee.exe
::Here specify your BAT/CMD Script File
set CallBAT=D:AutoTempCleanUp.bat
::E-Mail Settings (SMTP)
::———-x———
::If ‘yes’ a mail will be fired after backup
::~~~~~~~~~~~~~~~~~~~~
set _mailnotification=yes
::If ‘yes’ backup log will attached with mail
::~~~~~~~~~~~~~~~~~~~~
set attachment=no
::Type your e-mail address(for multiple e-mail ID, use ‘,’)
::~~~~~~~~~~~~~~~~~~~~
set email=To Mail Adress
:: Type from mail ID
::~~~~~~~~~~~~~~~~~~~~
set from=From Mail Address
::Set SMTP Server IP Address
::~~~~~~~~~~~~~~~~~~~~
set mserver=Your Mail Server IP
REM Settings End
Here is the complete script…
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | @echo off MODE CON: COLS=100 LINES=10 color 0c title ~: BAT File Log Generator :~ REM Settings Start ::Set Destination, source drive, and restore folder set LogPath=D:TCleanLog set LogName=TempCleanLog set LogExt=.log set WinTee=wtee.exe ::Here specify your BAT/CMD Script File set CallBAT=D:AutoTempCleanUp.bat ::E-Mail Settings (SMTP) ::----------x--------- ::If 'yes' a mail will be fired after backup ::~~~~~~~~~~~~~~~~~~~~ set _mailnotification=yes ::If 'yes' backup log will attached with mail ::~~~~~~~~~~~~~~~~~~~~ set attachment=no ::Type your e-mail address(for multiple e-mail ID, use ',') ::~~~~~~~~~~~~~~~~~~~~ set email=To Mail Adress :: Type from mail ID ::~~~~~~~~~~~~~~~~~~~~ set from=From Mail Address ::Set SMTP Server IP Address ::~~~~~~~~~~~~~~~~~~~~ set mserver=Your Mail Server IP REM Settings End :: get the date and time and then into single variable for /F "tokens=1-4 delims=/ " %%i in ('date /t') do ( set MM=%%j set DD=%%k set YYYY=%%l set date=%%k-%%j-%%l set dirdate=%%j%%k%%l ) ::Calling BAT /CMD File call %CallBAT% | %WinTee% %LogPath%%LogName%_%date%%LogExt% ::Full Log Path set flog=%LogPath%%LogName%_%date%%LogExt% if not "%_mailnotification%" == "yes" goto _end if not "%attachment%" == "yes" goto _noattach blat "%flog%" -attach "%flog%" -to %email% -s "%LogName% of %date%" -f "%from%" -server "%mserver%" > nul goto _skip :_noattach blat "%flog%" -to %email% -s "%LogName% of %date%" -f "%from%" -server "%mserver%" > nul :_end exit |
Download wtee.exe and blat.exe from following link and extract it to windows directory.
Windows.zip (62.7 KiB, 278 hits)
Disclaimer: All posts and opinions on this site are provided AS IS with no warranties. These are our own personal opinions and do not represent our employer’s view in any way.
This article currently have 11,650 views
This work is licensed under a Creative Commons Attribution-NoDerivatives 4.0 International License.