Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1525 connectés 

  FORUM HardWare.fr
  Programmation
  VB/VBA/VBS

  Probleme-à-la-con avec un script VBS

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

Probleme-à-la-con avec un script VBS

n°2170696
tompouss
Petit chat
Posté le 11-01-2013 à 11:21:06  profilanswer
 

Bonjour,
 
j'ai un Probleme-à-la-con avec un script: le retour à la ligne est foireux
 
c'est pas très joli quand je reçois un mail
 
le script en question:

Code :
  1. 'Ce script permet de parser un log robocopy pour detecter les erreurs de copies et d'envoyer le log par mail avec une alerte
  2. Dim txtSMTPServer, txtPort, txtTo, txtFrom, txtSubject, txtBodyOk, txtBodyFailure, txtLog, strValue, iTotal, iPos, strText
  3. '''''' A personnaliser ''''''''''''''''''''''''''''
  4.     txtSMTPServer = "127.0.0.1"
  5. txtPort = 24
  6. txtTo = "tbr@*****.be"
  7. txtFrom = "help@*******.be"
  8. txtSubject = "*****SQL backup status"
  9. txtBodyOk = "Your Robocopy Backup Job was successfully completed - attached file has details. " 
  10. txtBodyFailure = "Your Robocopy Backup Job has completed with one or more errors - attached file has details." 
  11.     txtLog = "C:\***********\robocopy\SQLBACKUPS.txt" 'chemin d'acces vers le log
  12.     txtErrorLevel = "C:\********\robocopy\errorlevelsql.txt"
  13.                
  14.  'gestion des erreurs robocopy
  15. ' strText = GetFile(txtLog)
  16. '   iPos = 1
  17.   '  Do While iPos <= Len(strText)
  18.    '    If InStr(iPos, UCase(strText), "0X00000" ) > 0 Then
  19.     '       iTotal = iTotal + 1
  20.      '           iPos = InStr(iPos, UCase(strText), "0X00000" )_
  21.       '          + Len("0X00000" )
  22.        '     Else
  23.         '        Exit Do
  24.          '   End If
  25.     'Loop
  26. strErrorlevel = GetFile(txtErrorLevel)
  27.     '-- --
  28.  
  29. 'preparation du mail
  30.            
  31.     Set sendmail = CreateObject("CDO.Message" )
  32. 'sendusing permet d'expliciter la facon d'envoyer le mail
  33. ' la valeur 2 utilise un client pour l'envoi du mail, il faut donc qu'il y en ai 1 d'installé et configuré
  34. 'la valeur 1 utilise le service smtp du server local (ou d'un server distant)
  35. 'http://msdn.microsoft.com/en-us/library/exchange/ms873037%28v=exchg.65%29.aspx
  36.     sendmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing" ) = 1
  37.     sendmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver" ) = txtSMTPServer
  38.     sendmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport" ) = txtPort
  39.     sendmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendemailaddress" ) = txtFrom
  40.     sendmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate" ) = 0
  41.     sendmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername" ) = "my@gmail.com"
  42.     sendmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword" ) = "password"
  43.     sendmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl" ) = false
  44.                
  45.     sendmail.Configuration.Fields.Update
  46.                
  47.     sendmail.From = txtFrom
  48.     sendmail.To = txtTo
  49.     sendmail.Subject = txtSubject
  50.    
  51. If strErrorlevel <= 3 Then
  52.  sendmail.Textbody = txtBodyOk  &  errorMessage(strErrorlevel) & vbNewline & "( Error level " & strErrorlevel &" )"
  53. else
  54.  sendmail.Textbody = txtBodyFailure &  errorMessage(strErrorlevel) & vbNewline & "( Error level " & strErrorlevel &" )"
  55.     End If
  56. 'on joint le log en attache
  57. sendmail.AddAttachment txtLog
  58.    
  59. 'Envoi du mail
  60. sendmail.Send
  61.    
  62. 'lecture du log
  63. function GetFile(txtLog)
  64.       If txtLog<>"" Then
  65.         Dim FS, FileStream
  66.         Set FS = CreateObject("Scripting.FileSystemObject" )
  67.           on error resume Next
  68.           Set FileStream = FS.OpenTextFile(txtLog)
  69.           GetFile = FileStream.ReadAll
  70.       End If
  71.     End Function
  72. function errorMessage(txtErrorLevel)
  73.  
  74.         if (txtErrorLevel >= 0 AND txtErrorLevel <= 16 ) Then
  75.             Select Case txtErrorLevel
  76.                 Case 0
  77.                     errorMessage = "No errors occurred, and no copying was done. The source and destination directory trees are completely synchronized. "
  78.                 Case 1
  79.                     errorMessage = "One or more files were copied successfully (that is, new files have arrived)."
  80.                 Case 2
  81.                     errorMessage = "Some Extra files or directories were detected. Examine the output log for details. "
  82.                 Case 3
  83.                     errorMessage = "Certains fichiers ont été copiés. Des files supplémentaires étaient présents. Aucune erreur ne s'est produite."
  84.                 Case 4
  85.                     errorMessage = "Some Mismatched files or directories were detected. Examine the output log. Some housekeeping may be needed."
  86.              
  87.                 Case 6
  88.                     errorMessage = "Il existe des fichiers supplémentaires et des fichiers qui ne correspondent pas. Aucun fichiers copiés et aucunr erreur apparue. Cela signifie que les fichiers existent déjà dans le répertoire de destination."
  89.                 Case 7
  90.                     errorMessage = "Les fichiers ont été copiés, une incompatibilité de fichier était présente et des fichiers supplémentaires étaient présents."
  91.                 Case 8
  92.                     errorMessage = "Some files or directories could not be copied (copy errors occurred and the retry limit was exceeded).Check these errors further."
  93.                 Case 16
  94.                     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."
  95.             End Select
  96.         else
  97.             errorMessage= "Unknow Error, please read the log"
  98.         end if
  99.     End Function


 
 
le retour à la ligne est foireux : je voudrais qu'il affiche
 
Your Robocopy Backup Job was successfully completed - attached file has details
Details de l'error level : Certains fichiers ont été copiés. Des files supplémentaires étaient présents. Aucune erreur ne s'est produite.
(Error level 3)
 
Quelqu'un aurait une idée ?
 
 

mood
Publicité
Posté le 11-01-2013 à 11:21:06  profilanswer
 

n°2170734
vave
Nice to meet me
Posté le 11-01-2013 à 14:52:04  profilanswer
 

Bonjour,
essaie de remplacer vbNewline par vbcrlf.


---------------
Bel ours Vave, je me dois de l’admettre. -Skyl"win"-  Mais toi tu es intelligent -Homerde- - Ce génie -SkylWINd- JDD S16M72 10:43:46 GMT-DTC +1
n°2170818
Marc L
Posté le 12-01-2013 à 11:11:52  profilanswer
 

 
              Ou sinon par vbLf …
 

n°2172045
tompouss
Petit chat
Posté le 21-01-2013 à 15:13:02  profilanswer
 

ca marche avec vbLf
 
merci

n°2172113
Marc L
Posté le 21-01-2013 à 19:32:23  profilanswer
 

 
              Merci pour ton retour !
 


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  VB/VBA/VBS

  Probleme-à-la-con avec un script VBS

 

Sujets relatifs
[VBS]Récupération de variables dans un fichier INIProblème script php tables croisées
Url rewriting problèmeAjax : problème (niveau Iut/Bts)
[C]Problème d'écriture avec fopen/fprintf et énumération bancaleVBS Renommer une ruche du registre
Erreur au lancement à distance script VBS[PHP/XML] Problème pour trouver le code PHP à partir du code VBS
[RESOLU] [VBS] Probleme script vbs 
Plus de sujets relatifs à : Probleme-à-la-con avec un script VBS


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR