Forums & Blog

A SmarterTools-sponsored community.
Welcome to Forums & Blog Sign in | Join | Help
in Search

SpamC Log Managment - Solution

Last post 10-10-2008 5:16 AM by dnsplus. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 04-13-2008 11:15 AM

    SpamC Log Managment - Solution

    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


     

    professional Uber Geek and proud owner/user of SmarterTools products
    dnsplus.net, chicago
  • 05-06-2008 4:01 AM In reply to

    Re: SpamC Log Managment - Solution

    I hope the community has found the above  scripts useful. I have been monitoring the performance of the scripts when they run under the configuration specified above, and i have determined that improved performance is needed.

     To this end, I am working on stream-lining the scripts and re-writing them under PowerShell to see if its faster. I will post the results and scripts once I have finished.

    - t

    professional Uber Geek and proud owner/user of SmarterTools products
    dnsplus.net, chicago
  • 10-10-2008 5:16 AM In reply to

    Re: SpamC Log Managment - Solution

    Well, its been a while since I wrote this posting, and I finally took the time to re-write the above script in powershell. The PS script runs much faster than the batch files. Give them a try and let me know what you think:

     ------------- sp_spamc_mover.ps1---------------

    ## This script will remove files older than a given date

    net use s: \\nas4100-01\smartermail /u:user password /persistent:no

    $folder = "c:\program files\smartertools\smartermail\service\smspamc\logs" # folder to test

    $archive = "s:\spamc_logs"

    #$archive = "$folder\temp"

    $NumHours = 2 # maximum age of file in days to allow

    $CurDate = get-date # current date

    $TestDate = $Curdate.Addhours(-$NumHours) # set TestDate

    $logFormat = Get-Date -format M.d.yyyy

    $logfile = "c:\scripts\logs\moved\spamc_logs_moved.$logFormat.log"

    $logCount = 0

    # ceate log file

    $strData = "Files Moved from: " + $folder + " on " + $CurDate

    $strData | out-file $logfile

    $jobStart = Get-Date -Format "HH:mm:ss.ms"

    #"Job Started: " + $jobStart | out-file -Append $logfile

    # get the files in the folder and determine if older than $NumDays

    get-childitem $folder | foreach { If ($_.GetType().Name -eq "FileInfo")

    {

    If ($_.LastWriteTime -lt $TestDate)

    {

    $logCount++

    $size = (Get-Item $folder\$_ | Measure-Object -Property length -sum).sum

    $logVolume = $logVolume + $size

    move $folder\$_ -destination $archive

    }

    }

    }

    $finished = get-date -Format "HH:mm:ss.ms"

    "Mover Started: " + $jobStart

    "Mover Finished: " + $finished | out-file -Append $logfile

    "Number of Files Moved: " + $logCount | out-file -Append $logfile

    "Messages marked as SPAM: " + $logCount | out-file -Append $logfile

    $totalVolume = ($logVolume/1024)/1024

    $sizeMoved = "{0:N2}" -f $totalVolume + " MB"

    "Total Size of Set: " + $sizeMoved | Out-File -Append $logfile

    $emailFrom = powershell@doman.com

    $emailTo = user@domain.com

    $subject = "SMSpamC Log Mover Report"

    $body = @"

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">

    <head>

    <meta http-equiv="Content-Language" content="en-us" />

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    <title>Untitled 1</title>

    <style type="text/css">

    .style1 {

    text-align: center;

    }

    .style2 {

    text-align: right;

    }

    </style>

    </head>

    <body>

    <div>

    <div class="style1">

    Your Company SmarterMail Scanner Report: SMSpamC Log Moves<br />

    <br />

    </div>

    <hr /><br />

    <table style="width: 65%" align="center">

    <tr>

    <td class="style2" style="width: 115px">Cleanup Started:</td>

    <td class="style1">$CurDate</td>

    </tr>

    <tr>

    <td class="style2" style="width: 115px">Cleanup Finished:</td>

    <td class="style1">$finished</td>

    </tr>

    <tr>

    <td class="style2" style="width: 115px">Messages Moved:</td>

    <td class="style1">$logCount</td>

    </tr>

    <tr>

    <td class="style2" style="width: 115px">File-set Size:</td>

    <td class="style1">$sizeMoved</td>

    </tr>

    </table>

    <br />

    <br />

    <hr /><br />

    </div>

    </body>

    </html>

    "@

    $smtpserver = "smtp_server / ip_address"

    $msg = New-Object Net.Mail.MailMessage

    $smtp = New-Object Net.Mail.SmtpClient($smtpserver)

    $msg.from = $emailFrom

    $msg.To.Add($emailTo)

    $msg.Subject = $subject

    $msg.IsBodyHtml = 1

    $msg.Body = $body

    $smtp.Send($msg)

    professional Uber Geek and proud owner/user of SmarterTools products
    dnsplus.net, chicago
Page 1 of 1 (3 items)