我目前有一个VBSCRIPT,它将获取错误日志的全部内容并通过电子邮件发送给用户,但我想修改它以便搜索"加载遇到的数据"如果出现,则将电子邮件发送到Error.log,否则,请不要附加日志并发送消息"加载成功"。 任何帮助将不胜感激!
Error.log的内容
fileEmail = "C:\Error.log"
intCount = 0
Set objStream = objFSO.OpenTextFile(fileEmail)
Do Until objStream.AtEndOfStream
sline = objStream.Readline
If intCount = 0 Then
objMessage.Subject = sline
Else
strMessage = strMessage & sline & vbcrlf
End If
intCount = intCount + 1
Loop
Const cdoAnonymous = 0 'Do not authenticate
Const cdoBasic = 1 'basic (clear-text) authentication
Const cdoNTLM = 2 'NTLM
strMessage = strMessage & vbcrlf
objMessage.From = "test@123.com"
objMessage.To = "test@123.com"
objMessage.TextBody = strMessage
objMessage.Configuration.Fields.Item _
("Microsoft URL") = 2
'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item _
("Microsoft URL") = "smtp.secureserver.net"
'Type of authentication, NONE, Basic (Base64 encoded), NTLM
objMessage.Configuration.Fields.Item _
("Microsoft URL") = cdoBasic
'Your UserID on the SMTP server
objMessage.Configuration.Fields.Item _
("Microsoft URL") = ""
'Your password on the SMTP server
objMessage.Configuration.Fields.Item _
("Microsoft URL") = ""
'Server port (typically 25)
objMessage.Configuration.Fields.Item _
("Microsoft URL") = 465
'Use SSL for the connection (False or True)
objMessage.Configuration.Fields.Item _
("Microsoft URL") = True
'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
objMessage.Configuration.Fields.Item _
("Microsoft URL") = 60
objMessage.Configuration.Fields.Update
objMessage.Send
Set objStream = Nothing
'Delete File when finished
objFSO.DeleteFile fileprocesslog, True
脚本到目前为止:
App\Console\Kernel.php
答案 0 :(得分:1)
InStr
function返回第一次出现在另一个字符串中的位置。应用它,例如如下:
sSearchFor = "Load data encountered"
booFound = False
sMessageSubj = "Log file empty"
fileEmail = "C:\Error.log"
intCount = 0
Set objStream = objFSO.OpenTextFile(fileEmail)
Do Until objStream.AtEndOfStream
sline = objStream.Readline
If intCount = 0 Then
sMessageSubj = sline
Else
strMessage = strMessage & sline & vbcrlf
End If
booFound = booFound Or ( Instr( 1, sline, sSearchFor, vbTextCompare) > 0)
intCount = intCount + 1
Loop
objStream.Close
Set objMessage = CreateObject("CDO.Message")
objMessage.From = "test@123.com"
objMessage.To = "test@123.com"
objMessage.Subject = sMessageSubj
If booFound Then
objMessage.AddAttachment fileEmail
strMessage = strMessage & vbcrlf
Else
strMessage = "Load was successful" & vbcrlf
End If
objMessage.TextBody = strMessage
' ''' remote SMTP server configuration section Begin '''
' ''' configure remote SMTP server here '''
' objMessage.Configuration.Fields.Update
' ''' remote SMTP server configuration section End '''
objMessage.Send
Const cdoAnonymous = 0 'Do not authenticate
Const cdoBasic = 1 'basic (clear-text) authentication
Const cdoNTLM = 2 'NTLM