Hello Folks,
I have been using SASpamC for a few weeks now, and if you have the logging turned on like I do, you may notice that your disk can fill up quickly with log files. I wrote two batch scripts that when run as scheduled tasks, prevent the system drive from filling up and crashing (for all intents and purposes) the SM mail sanning machine.
If you have any questions, or suggestions about the scripts, let me know.
System Setup:
Windows XP SP2 w SFU 3.5, running in a VMware guest (ESX 3.0.2)
1 CPU (PIII 1.4Ghz), 6GB SCSI Disk, 512M RAM, Standard resource shares
Dynamic Network Factory 1TB NAS-4100 (4x250GB, RAID5, NFS v3)
Note that SFU and NFS are not required. The same connectivity can be had using Microsoft Networking if the remote device supports it.
The flowing assumes you have the folder structure: C:\scripts and C:\scripts\logs
It also assumes that you have the FORFILES resourcekit utility installed (located in a folder that is in the PATH statement)
There are 2 sctipts: 1 moves files to another storage device (in my case the NAS), and 1 that does housekeeping on the NAS by deleting files that are older than 14 days.
Script 1: Spamc_mover.cmd (scheduled daily at 1am)
assumes there is a remote device with a netbios name and share called 'smartermail'
assumes that under the smartermail share, there is a folder called SpamC_Logs
Script 2: Spamc_delete.cmd (scheduled weekly, Saturdays 2am)
********* Begin Script 1 *******************
@echo OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SET LOGFILE=c:\scripts\logs\spamc_logs_moved.%date:~10,4%.%date:~7,2%.%date:~4,2%.log
echo Staring Cleanup >>%LOGFILE%
time /t>>%LOGFILE%
IF NOT EXIST s: (
net use s: \\<server_name>\smartermail /u:username password /persistent:no
goto PROCESS
) Else (
echo Drive mapping exists, proceeding ...
)
:PROCESS
SET _count=
SET _size=
SET _tsize=
SET _fsize=
cd\
cd "C:\Program Files\SmarterTools\SmarterMail\Service\SMSpamC\Logs"
rem produce a list of files in the logs directory (filename only)
FOR /F %%i in ('dir /b') do (
FOR /F "tokens=1 delims=-" %%j in ('dir /b %%i') do (
REM If the date-part of the log file is not the same as today, move it
IF NOT %%j == "%date:~10,4%%date:~4,2%%date:~7,2%" (
SET /A _tsize=%%~zi / 1024
SET /A _size=_size + _tsize
SET /A _count=_count + 1
MOVE %%i s:\SpamC_logs
)
)
)
SET /A _fsize=_size / 1024
echo Done.
time /t
echo Number of files moved: !_count!
echo Size of file set moved: !_fsize! MB
time /t>>%LOGFILE%
echo Number of files moved: !_count!>>%LOGFILE%
echo Size of file set moved: !_fsize!MB>>%LOGFILE%
cd\
cd scripts
net use s: /d /y
********* End Script 1 *********************
This next script can take a while to run, so have patience
********* Begin Script 2 *******************
@echo OFF
SETLOCAL ENABLEDELAYEDEXPANSION
set LOGFILE=c:\scripts\logs\spamc_log_deleted.%date:~10,4%.%date:~7,2%.%date:~4,2%.log
echo Staring Cleanup >>%LOGFILE%
if NOT EXIST s: (
net use s: \\<server_name>\smartermail /u:username password /persistent:no
goto PROCESS
) Else (
echo Drive Mapping Exists. Proceeding ...
)
:PROCESS
s:
cd spamc_logs
set _count=
set _size=
set _tsize=
set _fsize=
echo.
time /t
time /t >>%LOGFILE%
echo Renaming files to be deleted >>%LOGFILE%
echo Renaming files to be deleted ...
forfiles /m *.log /d -14 /c "cmd /c ren @file @file.arc"
echo Done Renaming>>%LOGFILE%
time /t>>%LOGFILE%
echo Done.
time /t
echo Deleting renamed files>>%LOGFILE%
echo Deleting renamed files ...
for /F %%i in ('dir /b *.arc') do (
set /A _count=_count + 1
set /A _tsize=%%~zi / 1024
set /A _size=_size + _tsize
del %%i
)
set /A _fsize=_size / 1024
echo Done.
time /t
echo Number of files deleted: !_count!
echo Size of file set deleted: !_fsize!MB
time /t>>%LOGFILE%
echo Number of files deleted: !_count!>>%LOGFILE%
echo Size of file set deleted: !_fsize!MB>>%LOGFILE%
c:
cd\
cd scripts
net use s: /d /y
********* End Script 2 *********************
Example output from the log files:
Mover:
Staring Cleanup
01:00 AM
Finished Cleanup
01:03 AM
Number of files moved: 1824
Size of file set moved: 133 MB
Deleter:
Staring Cleanup
02:29 AM
Renaming files to be deleted
Done Renaming
02:31 AM
Deleting renamed files
02:42 AM
Number of files deleted: 3382
Size of file set deleted: 168MB