<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Серый форум &mdash; VBS: отслеживание логов бэкапов]]></title>
		<link>https://forum.script-coding.com/viewtopic.php?id=5175</link>
		<atom:link href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=5175&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «VBS: отслеживание логов бэкапов».]]></description>
		<lastBuildDate>Wed, 17 Nov 2010 05:48:05 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: VBS: отслеживание логов бэкапов]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=41798#p41798</link>
			<description><![CDATA[<p>DnsIs, огромное спасибо! <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /></p>]]></description>
			<author><![CDATA[null@example.com (Elencheg)]]></author>
			<pubDate>Wed, 17 Nov 2010 05:48:05 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=41798#p41798</guid>
		</item>
		<item>
			<title><![CDATA[Re: VBS: отслеживание логов бэкапов]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=41794#p41794</link>
			<description><![CDATA[<div class="quotebox"><cite>Elencheg пишет:</cite><blockquote><p>...<br />2. Заранее проверяет в логе на наличие ошибок ( ключевое слово : error ). если они имеются - вывести в начало или заголовок письма.<br />...</p></blockquote></div><p>Не хотелось ковырять ваш скрипт, сделал с нуля небольшой примерчик.<br /></p><div class="codebox"><pre><code>Set objFSO = CreateObject(&quot;Scripting.FileSystemObject&quot;)

Const ForReading = 1
    &#039;ForReading=1 (файл открывается на чтение)
    &#039;ForWriting = 2 (файл открывается на запись)
    &#039;ForAppending=8 (файл открывается на добавление)
Const sFile = &quot;scripten_i.log&quot;
Set objFile = objFSO.OpenTextFile(sFile, ForReading)

Set objRegExp = CreateObject(&quot;VBScript.RegExp&quot;) &#039;создается объект регулярных выражений
objRegExp.Pattern = &quot;error&quot; &#039;что искать
objRegExp.IgnoreCase = True &#039;независимость от регистра символов

Dim arrFileLines()
i = 0
Do Until objFile.AtEndOfStream
    strLine = objFile.ReadLine &#039;Читаем 1 строку файла
    If objRegExp.Test(strLine) Then &#039;проверяем наличие слова error в строке
        WScript.Echo objRegExp.Test(strLine) &amp; VbCrLf &amp; strLine &#039;выводим строку, вы наверное удалите эту строку :)
        Redim Preserve arrFileLines(i) &#039;Пишем в массив
        arrFileLines(i) = objFile.ReadLine &#039; Пишем в массив
        i = i + 1
    End If
Loop
objFile.Close &#039;Закрываем файл

&#039;В итоге имеем массив arrFileLines(i) с ошибками, далее что хотим, то творим</code></pre></div><p>Измените переменную sFile под себя и все.</p>]]></description>
			<author><![CDATA[null@example.com (DnsIs)]]></author>
			<pubDate>Wed, 17 Nov 2010 04:58:22 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=41794#p41794</guid>
		</item>
		<item>
			<title><![CDATA[VBS: отслеживание логов бэкапов]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=41760#p41760</link>
			<description><![CDATA[<p>Добрый день. <br />Пытаюсь наклепать скриптик по отстеживанию логов бэпов.<br />Через поиск нашла уже примерно что-то похожее, но все же это не то...пробовала модернизировать - пока не получается (<br />логика работы такая: после прохождения очередного бэкапа запускается скрипт который:<br />1. смотрит лог файл&nbsp; и Отправляет логи как текст письма<br />2. Заранее проверяет в логе на наличие ошибок ( ключевое слово : error ). если они имеются - вывести в начало или заголовок письма.<br />3. Ну и собсственно если лога нет-тоже отправить письмо админ-ру.</p><br /><p>Пункты 1 и 3 реализованы, а вот 2 никак не удается......подскажите плз кто что может ) заранее спасибо )<br /></p><div class="codebox"><pre><code>Option Explicit
&#039; Dim variables
Dim oFSO, oWshNetwork, oCDO, oFolder, oFiles, oFile, oTextFile
dim strFileName, strComputerName, LogFile, ForReading

&#039; Create Objects
Set oFSO = CreateObject(&quot;Scripting.FileSystemObject&quot;)
Set oWshNetwork = WScript.CreateObject(&quot;WScript.Network&quot;)

&#039; Set constants
Const BACKUP_LOG_PATH = &quot;C:\Documents and Settings\&lt;backup user&gt;\Local Settings\Application Data\Microsoft\Windows NT\NTBackup\data&quot;
Const EMAIL_RECIPIENT = &quot;&lt;email&gt;&quot;

&#039; Set variable defaults
strFileName = &quot;&quot;
strComputerName = oWshNetwork.ComputerName

ForReading = 1

&#039; Start script
On Error Resume Next
Set oFolder = oFSO.GetFolder(BACKUP_LOG_PATH)
Set oFiles = oFolder.Files
For Each oFile in oFiles
If oFSO.GetExtensionName(oFile.Name) = &quot;log&quot; Then
If DateValue(oFile.DateLastModified) = Date() Then
LogFile = oFile.Name
strFileName = BACKUP_LOG_PATH &amp; &quot;\&quot; &amp; LogFile
EmailLog(strFileName)
&#039;Exit For
End If
End If
Next

If strFileName = &quot;&quot; Then
EmailError
End If

Sub EmailLog(logFilePath)

Set oCDO = CreateObject(&quot;CDO.Message&quot;)
Set oTextFile = oFSO.OpenTextFile(logFilePath, ForReading, false, -2)
Dim Text

Text = &quot;NTBackup log on &quot; &amp; strComputerName &amp; &quot; for &quot; &amp; Date() &amp; &quot; :&quot; &amp; vbCrlf &amp; vbCrlf

oCDO.Subject = &quot;Backup Log – &quot; &amp; strComputerName
oCDO.From = strComputerName &amp; &quot;@&lt;domain&gt;&quot;
oCDO.To = EMAIL_RECIPIENT

Do While Not (oTextFile.atEndOfStream)
Text = Text &amp; oTextFile.ReadLine &amp; vbCrlf
Loop

oCDO.TextBody = Text

oCDO.AddAttachment logFilePath

oCDO.Configuration.Fields.Item(&quot;http://schemas.microsoft.com/cdo/configuration/sendusing&quot;) = 2

oCDO.Configuration.Fields.Item(&quot;http://schemas.microsoft.com/cdo/configuration/smtpserver&quot;) =&quot;&lt;smtp server&gt;&quot;

oCDO.Configuration.Fields.Item(&quot;http://schemas.microsoft.com/cdo/configuration/smtpserverport&quot;) = 25

oCDO.Configuration.Fields.Item(&quot;http://schemas.microsoft.com/cdo/configuration/smtpauthenticate&quot;) = 1

oCDO.Configuration.Fields.Item(&quot;http://schemas.microsoft.com/cdo/configuration/sendusername&quot;) = &quot;&lt;send user&gt;&quot;

oCDO.Configuration.Fields.Item(&quot;http://schemas.microsoft.com/cdo/configuration/sendpassword&quot;) = &quot;&lt;send password&gt;&quot;

oCDO.Configuration.Fields.Update

oCDO.Send

set oCDO = Nothing

End Sub

Sub EmailError

Set oCDO = CreateObject(&quot;CDO.Message&quot;)

oCDO.Subject = &quot;Backup Log Missing – &quot; &amp; strComputerName
oCDO.From = strComputerName &amp; &quot;@&lt;domain&gt;&quot;
oCDO.To = EMAIL_RECIPIENT

oCDO.TextBody = &quot;No NTBackup log found on &quot; &amp; strComputerName &amp; &quot; for &quot; &amp; Date() &amp; &quot; !&quot;

oCDO.Configuration.Fields.Item(&quot;http://schemas.microsoft.com/cdo/configuration/sendusing&quot;) = 2

oCDO.Configuration.Fields.Item(&quot;http://schemas.microsoft.com/cdo/configuration/smtpserver&quot;) =&quot;&lt;smtp server&gt;&quot;

oCDO.Configuration.Fields.Item(&quot;http://schemas.microsoft.com/cdo/configuration/smtpserverport&quot;) = 25

oCDO.Configuration.Fields.Item(&quot;http://schemas.microsoft.com/cdo/configuration/smtpauthenticate&quot;) = 1

oCDO.Configuration.Fields.Item(&quot;http://schemas.microsoft.com/cdo/configuration/sendusername&quot;) = &quot;&lt;send user&gt;&quot;

oCDO.Configuration.Fields.Item(&quot;http://schemas.microsoft.com/cdo/configuration/sendpassword&quot;) = &quot;&lt;send password&gt;&quot;

oCDO.Configuration.Fields.Update

oCDO.Send

Set oCDO = Nothing

End Sub

set oFSO = Nothing
Set oWshNetwork = Nothing</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (Elencheg)]]></author>
			<pubDate>Tue, 16 Nov 2010 11:31:22 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=41760#p41760</guid>
		</item>
	</channel>
</rss>
