Advertisement

10.02.2008 at 11:22AM PDT, ID: 23782628
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.2

VBScript modification: Email formatting for log deletion script

Asked by baxleyb in VB Script

Tags:

Hello,

I have a .vbs script that is designed to delete files and logs that are older than a defined number of days.
The date is defined as the "cutoff" variable. The script is also designed to send an email after it deletes the logs and files.

In my current example only, the files contained in 2 directories are deleted (cleanup).
The production version will possibly delete all logs and files in about 10 directories.

What I would like to do is have the script send one email containing the name of the directory and a list of the files and logs that were deleted, for example

Accountsystem
1. Log 1
2. Log 2
3. Log 3

etc.

AsyncQueue
1. Log 1
2. Log 2
3. Log 3

etc.

Please let me know if there is a way to do this.

Thanks.Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
'<<<<<<<<<<<<DEFINE VARIABLES HERE-BEGIN>>>>>>>>>>>>>>>>>>
DIM cutoff, curyear, scriptStatus, mailto, mailfrom, maillog
'DEFINE CUTOFF DATE (LOG FILES OF DATES OLDER THAN THIS DATE SHOULD BE DELETED)
'SPECIFY CUTOFF DATE IN CENTER PARAMETER
	cutoff = dateadd("d", -10, date)'wscript.echo "Cut off=" & cutoff
'GET CURRENT YEAR FOR REGULAR EXPRESSION TO PERFORM LOG DELETION 
	curyear = year(now) 'wscript.echo "Current Year=" & curyear
'PARAMETER TO ENABLE LOGS TO BE DELETED
'SET TO 'ON' TO ENABLE 'OFF' TO DISABLE
	scriptStatus = "ON"
'EMAIL TO ADDRESS (Add multiple by seperating with commas)
	mailto = "me@me.com"
'EMAIL FROM ADDRESS (Add multiple by seperating with commas)
	mailfrom = "me@me.com"
'<<<<<<<<<<<<DEFINE VARIABLES HERE-END>>>>>>>>>>>>>>>>>>
 
'++++++++++++++++++++++++EMAIL CONFIGURATION BEGIN++++++++++++++++++++++++++++++++++
set maillog = createobject("CDO.Message") 
'This section provides the configuration information for the remote SMTP server.
maillog.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'Send the message using the network (SMTP over the network).
maillog.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") ="mx01exchange.me.com"
maillog.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 
maillog.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False 'Use SSL for the connection (True or False)
maillog.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 30
maillog.Configuration.Fields.Update
'End remote SMTP server configuration section==
maillog.from = mailfrom
maillog.to = mailto
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
if scriptStatus = "ON" then
'DELETE ALL RDTemp FILES
arrayHeaders = array("AccountSystem", "AsyncQueue")
arrayTotal = UBound(arrayHeaders)
'wscript.echo arrayHeaders(0)
 
	if arrayHeaders(0) = "AccountSystem" then
	'DELETE ALL ACCOUNTSYSTEM LOG FILES
	cleanup  "D:\MyApp\LOG\Accountsystem", "^"&curyear& ".*?\.log$", cutoff
	if arrayHeaders(1) = "AsyncQueue" then
	'DELETE ALL ASYNCQUEUE LOG FILES
	cleanup  "D:\MyApp\LOG\AsyncQueue", "^"&curyear& ".*?\.xml$", cutoff
	end if
	end if
''''''''''''''''''''''''''''''''''''''''''''''''
 
'-------------------------------------------------------------------------------------------------------------
 
 
'--------------------------------------------------------------------------------------------------------------
 
 
'******************FUNCTIONS USED TO DELETE FILES************************************
Sub cleanup(folderName, pattern, cutoff)
Set fso = createobject("scripting.filesystemobject")
Set folder = fso.getfolder(folderName)
Set files = folder.files
Set re = new regexp
	re.Pattern = pattern
	countFiles = 0
	countSize = 0
	file = j
For each file in files
	  
 If re.Test(file.name) Then
 If file.datelastmodified < cutoff Then
 'wscript.echo "Deleting " & file.name &" last modified: " & file.datelastmodified
 'wscript.echo countFiles
 'wscript.echo "Clean up=" & cleanup
 
 countFiles = countFiles + 1
 countSize = countSize + file.Size
 strbody = strbody &vbCrLf & countFiles & ":" &  "Deleted" & file.name &" last modified: " & file.datelastmodified & vbCrLf
 maillog.textbody = strbody
 
countFilesFINAL = countFiles
 On Error Resume Next
 file.delete
 End If
 End If
 	
Next
 
'wscript.echo "Deleted " & countFiles & " files from " & folderName & " [" & niceSize(countSize) & "]"
 
maillog.subject = "ATTENTION: "&countFilesFINAL& " logs and files older than " & cutoff & " have been deleted"
 Set re = Nothing
 Set files = Nothing
 Set folder = Nothing
 Set fso = Nothing
'maillog.subject = "ATTENTION: "&countFilesFINAL& " logs and files older than " & cutoff & " have been deleted"
 End Sub
 
 
Function niceSize(size)
 units = "B"
 If size > 1024 Then
 size = Round(size / 1024, 1)
 units = "kB"
 End If
 If size > 1024 Then
 size = Round(size / 1024, 2)
 units = "MB"
 End If
 If size > 1024 Then
 size = Round(size / 1024, 3)
 units = "GB"
 End If
 niceSize = "" & size & units
End Function
'*************************************************************************************
elseif scriptStatus = "OFF" then
maillog.subject = "ATTENTION: RE: The RedDot logs and files deletion script did not run properly"
	cleanupOFF = "The script is turned off"
	'wscript.echo cleanupOFF
	strbody = cleanupOFF
	maillog.textbody = strbody
end if
 
maillog.send
Set maillog = nothing
[+][-]10.03.2008 at 12:31AM PDT, ID: 22631776

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]10.07.2008 at 01:15PM PDT, ID: 22663253

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.08.2008 at 04:59PM PDT, ID: 22674501

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]10.14.2008 at 12:12PM PDT, ID: 22714923

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: VB Script
Tags: VScript
Sign Up Now!
Solution Provided By: baxleyb
Participating Experts: 1
Solution Grade: A
 
 
[+][-]10.14.2008 at 12:16PM PDT, ID: 22714967

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 - Hierarchy / EE_QW_2_20070628