Old log removal script

This section contains scripts that hMailServer has contributed with. hMailServer 4 is needed to use these.
Post Reply
bladerunner
Normal user
Normal user
Posts: 102
Joined: 2008-05-25 11:15

Old log removal script

Post by bladerunner » 2008-05-28 11:24

'
' note: the awstats log file is not deleted as his date is updated by daily changes :)
'
Dim Fso

Dim Directory

Dim Modified

Dim Files


strLogFIleSuffix = ".log"

' change following installation...
strPath = "C:\Programmi\hMailServer\Logs"

' how many days to allow...
intDaysOld = 3

Set Fso = CreateObject("Scripting.FileSystemObject")

Set Directory = Fso.GetFolder(strPath)


Set Files = Directory.Files

For Each Modified in Files

If DateDiff("D", Modified.DateLastModified, Now) > intDaysOld and lcase(right(Modified,4))=strLogFIleSuffix Then
' uncomment when sure it works fine ! check before run
' Modified.Delete
WScript.Echo(" Will delete " & Modified.Name)
end if

Next

jbaitz
New user
New user
Posts: 18
Joined: 2008-12-10 20:52

Re: Old log removal script

Post by jbaitz » 2008-12-10 20:58

Bladerunner...I am not able to get the script to delete the log files. When I uncomment the delete line it no longer displays the list of files to be deleted and doesn't clear any of my log files.

I have changed the path to point to my hmail server logs and I have changes the number of days to 14 which is what we want to keep.

When I run the script with the delete commented out it lists the files I would expect it to however that doesn't occur nor does the delete once I uncomment the delete line.

Thanks

Justin

Schnurps
New user
New user
Posts: 9
Joined: 2008-12-04 22:51

Re: Old log removal script

Post by Schnurps » 2008-12-10 21:57

To really delete Files the Script has to look like this:

Code: Select all

Dim Fso

Dim Directory

Dim Modified

Dim Files


strLogFileSuffix = ".log"

' change following installation...
strPath = "C:\Programmi\hMailServer\Logs"

' how many days to allow...
intDaysOld = 30

Set Fso = CreateObject("Scripting.FileSystemObject")

Set Directory = Fso.GetFolder(strPath)


Set Files = Directory.Files

For Each Modified in Files

If DateDiff("D", Modified.DateLastModified, Now) > intDaysOld and lcase(right(Modified,4))=strLogFIleSuffix Then
' uncomment when sure it works fine ! check before run
Modified.Delete
'  WScript.Echo(" Will delete " & Modified.Name)
end if

Next
Hope this helps....

jbaitz
New user
New user
Posts: 18
Joined: 2008-12-10 20:52

Re: Old log removal script

Post by jbaitz » 2008-12-10 23:02

Thanks that made it work.....I hadn't commented out the Wscript line.

Thanks

Justin

bladerunner
Normal user
Normal user
Posts: 102
Joined: 2008-05-25 11:15

Re: Old log removal script

Post by bladerunner » 2008-12-10 23:20

yes sorry, a small type mistake
the delete statement does the deletion....
other is just a prompt, to be removed in a batch safe environment

User avatar
Caspar
Senior user
Senior user
Posts: 377
Joined: 2008-09-08 11:47
Contact:

Re: Old log removal script

Post by Caspar » 2008-12-12 16:04

what kind of extension do you need to save this script in?
If you have strange problems or errors use the log analyzer! http://log.damnation.org.uk
Join us on IRC! http://hmailserver.com/irc_fullscreen.php

User avatar
mattg
Moderator
Moderator
Posts: 20792
Joined: 2007-06-14 05:12
Location: 'The Outback' Australia

Re: Old log removal script

Post by mattg » 2008-12-12 16:57

looks like .vbs to me
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

bladerunner
Normal user
Normal user
Posts: 102
Joined: 2008-05-25 11:15

Re: Old log removal script

Post by bladerunner » 2009-04-05 09:01

obv this script works for version 5.x and 6.x too :)

LesD
Senior user
Senior user
Posts: 343
Joined: 2009-01-15 20:22
Location: London, UK.

Re: Old log removal script

Post by LesD » 2009-04-24 13:07

Before using the script I wanted to understand what it does.

There is one thing that foxes me.

The is a decleration for "Modified" and it is then used to control the loop but I cannot see where it is set. What does it represent?

LesD
Senior user
Senior user
Posts: 343
Joined: 2009-01-15 20:22
Location: London, UK.

Re: Old log removal script

Post by LesD » 2009-04-24 13:51

Sorry - I was being thick! The For loop sets it. This is not quite the syntax that I am used to.

Post Reply