Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need script to run at server 1

Status
Not open for further replies.

haytatreides

IS-IT--Management
Oct 14, 2003
94
US
Please forgive me, i am new to vbscript, so if i say anything stupid, feel free to laugh at me as i probably won't hear it.

I need a server to fire off emails based on a value in my sql server database. the emails need to have data from another table, and fire automatically. i was told that writting a script and running it as a scheduled task would be the easiest and best way to do this. i have seen previous posts on here suggest that, but i have no idea how to write the script. i have coded in vb6 and c++ and java, so i am not new to coding, just vbscript.

Any help would be greatly appreciated. I will name my first born after you. Thanks

--hayt
 
You will need to figure out the part about getting your table info, but this sample should give you all you need for getting the email out.

This script is designed to use a service name as an argument and emails me when a service fails two times. Should be easy enough for you to tweak it.

'==========================================================================
'
' VBScript Source File --
'
' NAME: NotifySvcFailure.vbs
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' DATE : 04/15/2003
'
' COMMENT:
'
' This script can be added to a services actions to be taken on failure
'
' You must customize the entries for oDomain and oMyIP with the proper company information.
' Items to customize are on lines 28 and 30.
'=====================================

Dim oName, ODomain, oMyIP, oTo, svcName

Set svcName = WScript.Arguments

' Get the computer name
Set WshNetwork = CreateObject("WScript.Network")
oName = WshNetwork.ComputerName

' Set the company specific information

' Company Internet Domain Name
ODomain = "myhouse.com"
' Set the SMTP server IP
oMyIP = "68.6.19.4"
' Where do you want the message to be delivered
oTo = "support@thespidersparlor.com"


' Set the visual basic constants as they do not exist within VBScript.
' Do not set your smtp server information here.
Const cdoSendUsingMethod = " _
cdoSendUsingPort = 2, _
cdoSMTPServer = "
'Create the CDO connections.
Dim iMsg, iConf, Flds
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
Set Flds = iConf.Fields

'SMTP server configuration.
With Flds
.Item(cdoSendUsingMethod) = cdoSendUsingPort

'Set the SMTP server address here.
.Item(cdoSMTPServer) = oMyIP
.Update
End With

'Set the message properties.
With iMsg
Set .Configuration = iConf
.To = oTo
.From = oName & "@" & oDomain
.Subject = "Service Failure"
.TextBody = "Service " & svcName & " on Server " & oName & " at company " & ODomain & " failed 2 times, the time of failure was " & now
End With

'An attachment can be included.
'iMsg.AddAttachment Attachment

'Send the message.
iMsg.Send

'MsgBox "Done"

I hope you find this post helpful. Please let me know if it was.

Regards,

Mark
 
Thanks man, this is a huge help. the only book i have on scripts is an O'reilly book, and pretty much the only information i got out of it is the bio of the animal on the cover. the whole thing is web based scripts. thanks man.


If anyone has any information on pulling fields from a sql database, i would appreciate it.

hayt

PS - Mark gets first dibs on naming my first child.
 
I'll release you on the bond for naming of the first child.
:)
Don't want you to get in trouble with the wife!


I hope you find this post helpful. Please let me know if it was.

Regards,

Mark
 
I may have run into a snag....

i dont know if i am actually having this problem, but my brain has been slow lately, and it just caught up to me.

Dont i need to have a username and password to access my smtp server??? i forgot to tell you that my smtp server is off site. it is not handled locally (although, soon will have mailer daemon). am i needlessly worrying?

thanks
hayt
 
nevermind, ignore my last post. it worked like a charm! thanks.
 
For the sql issue, you can take a look here: thread329-781059

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
is it possible to convert this script to run from html??? and how?
 
I think this shoud run is ASP without a problem but have not tested it. Just enclose the script in script tags and be sure to specify that the script language is VBScript at the top. Example:

<%@ LANGUAGE="VBSCRIPT" %>

<html>
<HEAD>
<TITLE>Test</TITLE>
<BODY>
<%

Script Code

%>

HTML CODE

</BODY>
</HTML>

I hope you find this post helpful. Please let me know if it was.

Regards,

Mark
 
Got it, had to make some changes, but runs as html if i take out the wscript and such.

hayt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top