KS-Soft. Network Management Solutions
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister    ProfileProfile    Log inLog in 

Delete files older than. . .

 
Post new topic   Reply to topic    KS-Soft Forum Index -> Configuration, Maintenance, Troubleshooting
View previous topic :: View next topic  
Author Message
greyhat64



Joined: 14 Mar 2008
Posts: 246
Location: USA

PostPosted: Tue Apr 07, 2009 2:28 pm    Post subject: Delete files older than. . . Reply with quote

I'm not seeing it, so it must be there. . .
I see where the Count Files test can note "Files older than xx days".
Can this be used to execute a delete action on any files that meet the criteria, or is this going to be another script writing exercise?
It would even help if the test could generate a 'file list' that could be passed to an action script.
Regards,
Joel
Back to top
View user's profile Send private message Send e-mail
KS-Soft



Joined: 03 Apr 2002
Posts: 12791
Location: USA

PostPosted: Tue Apr 07, 2009 3:35 pm    Post subject: Reply with quote

If HostMonitor can provide such list, you still need to create script to process the list and remove the files. So, why do the same job twice?
I think you may create script that will remove old files. Something like this
Code:
const TargetFolder = ""c:\targetfolder\"
const MaxAge = 60

Dim FSO, fsFolder, item
Set FSO = CreateObject("Scripting.FileSystemObject")
Set fsFolder = fso.GetFolder(TargetFolder)
For each item in fsFolder.Files
  If DateDiff("n", Item.DateLastModified, Date+Time)>MaxAge
     Then Item.Delete
  End If
Next


Regards
Alex
Back to top
View user's profile Send private message Visit poster's website
Paul_NHS



Joined: 25 Feb 2009
Posts: 59

PostPosted: Wed Apr 08, 2009 1:37 am    Post subject: Reply with quote

We use this.

cheers, Paul
Code:
Option Explicit
' **
------------------------------------------------------------------------
' ** -- Description:    Deletes files older than a specified number of days
' ** --                 from the folder identified.
' ** --
' ** -- Parameters:        1 - The folder that is to cleaned out
' ** --                    2 - The number of days old the file must be before
' ** --                        they are deleted.
' ** --                   
' ** -- e.g. To clean out files older than 5 days from the c:\temp folder you would have:
' ** -- cscript.exe "path\CleanUpFolder.vbs" c:\temp 5
' ** --
' ** -- Called by:     
' ** -- Calls:         
' ** --
' ** -- Created:          16/07/03 by Paul Pettigrew
' ** --
' ** -- Modified:   
' ** --
' **
------------------------------------------------------------------------

Dim objFSO
Dim objFolder
Dim objFileCollection
Dim objFile
Dim colArguments
Dim strFolderPath
Dim strDays
Dim intDays
Dim blnContinue
Dim dteCutoff


blnContinue = False

' ** -- Read in the Command line parameters
Set colArguments = Wscript.Arguments
If colArguments.Count = 2  Then
    strFolderPath = colArguments(0)
    strDays = colArguments(1)

    ' ** -- Check that the parameters look reasonable
    If Len(strFolderPath) > 0 Then
        If Len(strDays) > 0 Then
            intDays = 0 - CInt(strDays)
            blnContinue = True
        End If
    End If
End If

If blnContinue = True Then
    Set objFSO = CreateObject("Scripting.FileSystemObject")

    ' ** -- Check if the specified Folder exists
    If objFSO.FolderExists(strFolderPath) Then
        Set objFolder = objFSO.GetFolder(strFolderPath)
        Set objFileCollection = objFolder.Files

        ' ** -- Calculate the Cutoff date
        dteCutoff = DateAdd("D", intDays, Now)
       
        ' ** -- Loop through the Folder looking for the old files
        For each objFile in objFileCollection
            If objFile.DateLastModified < dteCutoff Then
                objFile.Delete True
            End If
        Next
       
        ' ** -- Clean Up
        Set objFile = Nothing
        Set objFileCollection = Nothing
        Set objFolder = Nothing
    End If
   
    Set objFSO = Nothing
End If
Back to top
View user's profile Send private message
greyhat64



Joined: 14 Mar 2008
Posts: 246
Location: USA

PostPosted: Wed Apr 08, 2009 11:11 am    Post subject: Reply with quote

Paul,
You never cease to amaze me!

After a discussion with the requester I'm changing strategies. This group does 'mock ups' in this Temp folder which is comprised of a bunch of subfolders. Because of the way it is used there may be file dependencies, so simple creation/modification dates are unusable, lest you break up the 'set'.

I haven't worked out all the details but my current logic is to look at top level folder creation/modification date, but even that is not entirely reliable. Once I've found a 'stale' folder the action will be to notify the owner/manager. I've yet to figure out what to do from there. I guess I could nag them incessantly until they delete/move it.

What a kludge.

Alex,
Maybe Paul would let you include this script in the list of standard shell scripts for v8 if you are real nice to him.
I'd like to se a growing list of 'test method specific' actions like this included - either as shell script examples, or as builtin actions associated with the test method.
Back to top
View user's profile Send private message Send e-mail
KS-Soft



Joined: 03 Apr 2002
Posts: 12791
Location: USA

PostPosted: Wed Apr 08, 2009 3:11 pm    Post subject: Reply with quote

We don't want to include such script as "Shell Script" test method. No way!
It removes files and I am sure some people will remove important files from the system while testing HostMonitor.
TEST should NOT modify system!! Test should check the system without changing any settings.

Regards
Alex
Back to top
View user's profile Send private message Visit poster's website
greyhat64



Joined: 14 Mar 2008
Posts: 246
Location: USA

PostPosted: Wed Apr 08, 2009 11:58 pm    Post subject: Reply with quote

Ok, Ok - it was just a suggestion
But I will say that I'm probably not alone in looking at every test method and thinking, "What can I DO with it? What kind of action can I take based on the results?" This is just one example of an action that can be taken based on a simple file/folder examination. The more examples given to the new user the broader/deeper the adoption of the product.
I love AHM and I really like what Paul did with this script - I was just showing some appreciation.
Back to top
View user's profile Send private message Send e-mail
Paul_NHS



Joined: 25 Feb 2009
Posts: 59

PostPosted: Thu Apr 09, 2009 2:02 am    Post subject: Reply with quote

Thanks for the compliment, but I can't even claim this one as mine - although I did ask the bod who wrote it to write it (is that good English?!). I just use it everywhere I go - the joys of contracting

cheers, Paul
Back to top
View user's profile Send private message
Robert_in_MTL



Joined: 20 Jun 2006
Posts: 229
Location: Montreal, Quebec

PostPosted: Thu Feb 22, 2018 9:49 am    Post subject: Reply with quote

Hi Sorry to revive this old post...
I am trying to implement this and I am almost successful lol

I want to delete older backups in a folder but make sure that I keep at least x number of files in case the backups cease to be done, ( keeps at least a number of backups)

I installed a local agent on the server where the backups are, lets say d:\backups\

test#1: executed by local agent, count files, if filecount is more then X , become bad

test #2: executed by local agent, Active Script, depends on test #1, execute script described above like this:

D:\IT\Scripts\CleanOldFiles.vbs D:\CISCO_Backups 5


If I execute it, it returns: Cannot open file

"C:\WINDOWS\system32\"D:\IT\Scripts\CleanOldFiles.vbs" D:\CISCO_Backups 5". The filename, directory name, or volume label syntax is incorrect

I know I am close and it's maybe just a tweak I need to do, do you have a hint for me?

Thanks
Back to top
View user's profile Send private message
KS-Soft



Joined: 03 Apr 2002
Posts: 12791
Location: USA

PostPosted: Thu Feb 22, 2018 10:14 am    Post subject: Reply with quote

Its better to create new thread than find some 9 years old...

So you set "D:\IT\Scripts\CleanOldFiles.vbs" as parameter of Execute external program action? While RMA returns error related to "C:\WINDOWS\system32\"D:\IT\Scripts\CleanOldFiles.vbs"?
RMA version?

Regards
Alex
Back to top
View user's profile Send private message Visit poster's website
Robert_in_MTL



Joined: 20 Jun 2006
Posts: 229
Location: Montreal, Quebec

PostPosted: Thu Feb 22, 2018 10:47 am    Post subject: Reply with quote

KS-Soft wrote:
Its better to create new thread than find some 9 years old...


Yes, I know, found it by searching and it is directly related to the script Paul posted...

KS-Soft wrote:

So you set "D:\IT\Scripts\CleanOldFiles.vbs" as parameter of Execute external program action? While RMA returns error related to "C:\WINDOWS\system32\"D:\IT\Scripts\CleanOldFiles.vbs"?
RMA version?

Regards
Alex


RMA is 6.10, runs as service as administrator from a domain account

I need to send parameters to the script

The parameter is exactly this:
D:\IT\Scripts\CleanOldFiles.vbs D:\CISCO_Backups 5

but I tried
"D:\IT\Scripts\CleanOldFiles.vbs" D:\CISCO_Backups 5

and
"D:\IT\Scripts\CleanOldFiles.vbs D:\CISCO_Backups 5"


The test itself replies
Code:
cannot open file "D:\IT\scripts\cleanoldfiles.vbs D:\CISCO_Backups 5". the filename, directory name, or volume label syntax is incorrect


If I only type D:\IT\Scripts\CleanOldFiles.vbs, it still does not find it
Back to top
View user's profile Send private message
KS-Soft



Joined: 03 Apr 2002
Posts: 12791
Location: USA

PostPosted: Thu Feb 22, 2018 11:20 am    Post subject: Reply with quote

Sorry, its still unclear what exactly command line is used, could you please send screen shot of the action settings to support@ks-soft.net?)
(HostMonitor and RMA cannot process scripts, so normally you start vbs scripts using cscript.exe command)

Regards
Alex
Back to top
View user's profile Send private message Visit poster's website
Robert_in_MTL



Joined: 20 Jun 2006
Posts: 229
Location: Montreal, Quebec

PostPosted: Thu Feb 22, 2018 12:27 pm    Post subject: Reply with quote

ah!
there you have it, I must use cscript
I was calling the .vbs script directly.

I will search for that in the helpfile and try to make it work
Thanks
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    KS-Soft Forum Index -> Configuration, Maintenance, Troubleshooting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group

KS-Soft Forum Index