tompouss Petit chat | Mieux comme ca J'ai quand meme eu un errorlevel 0 sur un backup où il ya eu des changements
Je pense que ce serait mieux de reinitialiser la variable errorlevel à la fin du job
Code :
- 'Ce script permet de catcher l'error-level généré suite à un job robocopy pour detecter les erreurs de copies et d'envoyer le log par mail avec une alerte
- Dim Jobname, txtSMTPServer, txtPort, txtTo, txtFrom, txtSubject, txtBodyOk, txtBodyFailure, txtLog, strValue, iTotal, iPos, strText
- Set WshShell = CreateObject("WScript.Shell" )
- '''''' A personnaliser ''''''''''''''''''''''''''''
- Jobname = "*****"
- txtSMTPServer = "******l"
- txtPort = 24
- txtTo = "it@******.be"
- txtFrom = "help@********.be"
- txtSubject = "*********
- txtBodyOk = "Your Robocopy Backup Job was successfully completed - attached file has detail" & vbLf
- txtBodyFailure = "Your Robocopy Backup Job has completed with one or more errors - attached file has details."& vbLf
- txtLog = "C:\********\robocopy\BACKUPMERCATORS.txt" 'chemin d'acces vers le log
- 'txtErrorLevel = "C:\*********\robocopy\errorlevelmercator.txt"
- errorlevel = WshShell.Run( Jobname, 0, true)
-
- 'gestion des erreurs robocopy
- 'strText = GetFile(txtLog)
- 'iPos = 1
- ' Do While iPos <= Len(strText)
- ' If InStr(iPos, UCase(strText), "0X00000" ) > 0 Then
- ' iTotal = iTotal + 1
- ' iPos = InStr(iPos, UCase(strText), "0X00000" )_
- ' + Len("0X00000" )
- ' Else
- ' Exit Do
- ' End If
- 'Loop
- 'strErrorlevel = GetFile(txtErrorLevel)
- '-- --
-
-
- 'preparation du mail
-
- Set sendmail = CreateObject("CDO.Message" )
- 'sendusing permet d'expliciter la facon d'envoyer le mail
- ' la valeur 2 utilise un client pour l'envoi du mail, il faut donc qu'il y en ai 1 d'installé et configuré
- 'la valeur 1 utilise le service smtp du server local (ou d'un server distant)
- 'http://msdn.microsoft.com/en-us/library/exchange/ms873037%28v=exchg.65%29.aspx
- sendmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing" ) = 1
- sendmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver" ) = txtSMTPServer
- sendmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport" ) = txtPort
- sendmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendemailaddress" ) = txtFrom
- sendmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate" ) = 0
- sendmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername" ) = "my@gmail.com"
- sendmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword" ) = "password"
- sendmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl" ) = false
-
- sendmail.Configuration.Fields.Update
-
- sendmail.From = txtFrom
- sendmail.To = txtTo
- sendmail.Subject = txtSubject
-
- If errorlevel <= 3 Then
- if errorlevel = -1 Then
- sendmail.Textbody = "No error-level catched, check log"
- else
- sendmail.Textbody = txtBodyOk & " Error-level "&errorlevel & vbLf &"Error details = " & errorMessage(errorlevel)
- end if
- else
- sendmail.Textbody = txtBodyFailure & " Error-level :"&errorlevel & vbLf &"Error details = " & errorMessage(errorlevel)
- End If
- 'on joint le log en attache
- sendmail.AddAttachment txtLog
-
- 'Envoi du mail
- sendmail.Send
- function errorMessage(errorlevel)
-
- if (errorlevel >= 0 AND errorlevel <= 16 ) Then
- Select Case errorlevel
- Case 0
- errorMessage = "No change: No errors occurred, and no copying was done. The source and destination directory trees are completely synchronized. "
- Case 1
- errorMessage = "One or more files were copied successfully (that is, new files have arrived)."
- Case 2
- errorMessage = "Some Extra files or directories were detected. Examine the output log for details."
- Case 3
- errorMessage = "One or more files were copied successfully (that is, new files have arrived). Some Extra files or directories were detected. Examine the output log for details."
-
- Case 4
- errorMessage = "Some Mismatched files or directories were detected. Examine the output log. Some housekeeping may be needed."
- Case 5
- errorMessage = "OKCOPY + MISMATCHES"
- Case 6
- errorMessage = "MISMATCHES + XTRA"
- Case 7
- errorMessage = "OKCOPY + MISMATCHES + XTRA"
- Case 8
- errorMessage = " Some files or directories could not be copied (copy errors occurred and the retry limit was exceeded) Check these errors further."
- Case 9
- errorMessage = "One or more files were copied successfully but Some files or directories could not be copie (copy errors occurred and the retry limit was exceeded). Check these errors further."
- Case 10
- errorMessage = "FAIL + XTRA"
- Case 11
- errorMessage = "OKCOPY + FAIL + XTRA"
- Case 12
- errorMessage = "FAIL + MISMATCHES"
- Case 13
- errorMessage = "OKCOPY + FAIL + MISMATCHES"
- Case 14
- errorMessage = "FAIL + MISMATCHES + XTRA"
- Case 15
- errorMessage = "OKCOPY + FAIL + MISMATCHES + XTRA"
- Case 16
- errorMessage = "Serious error. Robocopy did not copy any files. Either a usage error or an error due to insufficient access privileges on the source or destination directories."
- End Select
- else
- errorMessage= "Unknow Error, please read the log"
- end if
- End Function
|
|