|
Answer» Hi i am totally new to the Batch file concept.
I have created a batch file which zip the sever logs month wise and then delete those logs. But when i delete that zip file, my batch file will send a mail on my ID.
So if any changes needed to be done please do suggest.
Thank you.
This is my code:-
echo off
rem Findout Month, Year and DATE FOR /F "tokens=1,2,3,4 delims=/ " %%A in ('Date /t') do set year=%%D FOR /F "tokens=1,2,3,4 delims=/ " %%A in ('Date /t') do set month=%%B FOR /F "tokens=1,2,3,4 delims=/ " %%A in ('Date /t') do set day=%%C
rem Solve problem Year start and adding 0 in month if %month% EQU 01 ( set month=12 set /a year=%year%-1 ) else ( set /a month=%month%-1 ) if %month% LSS 10 set month=0%month%
rem Set file names for last month file. set lastmonthfiles=server.log.%year%-%month%-
rem To compress the file. :compress "C:\Program Files\7-Zip\7z.exe" a -y "bkp-%lastmonthfiles%.zip" %lastmonthfiles%* ping -n 15 192.168.100.44 > nul if Not exist bkp-%lastmonthfiles%.zip ( echo zipping failed pause CALL mail2.bat ) else ( DEL %lastmonthfiles%* )
This is the code for mail2.bat file. I have used bmail into it.
bmail -s karina -t [email protected] -f [email protected] -h -a backupPlease do not post the same question more than once. I deleted the duplicates.I think that this should handle the date issue in a region insensitive way: not tested
Code: [Select]echo off for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a" set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"
if "%MM%"=="01" (set /a YYYY=YYYY-1 & set "MM=12") else (set /a MM=1%MM% - 1)
set lastmonthfiles=server.log.%YYYY%-%MM:~-2%- actually Allan the SCRIPT you deleted was the different. I asked about how to send mail from my batch file if zipping fails. And into new script i did mentioned that the file which i have created is sending the mails if zipping get fails. But still thanks
|