Announcement

Collapse
No announcement yet.

VBScript send from log NTBackup

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • VBScript send from log NTBackup

    Now ,This is script send log from NTBackup to email via attachment file log in email

    but i need to write log on body message and send to my email how to revise ?







    Set objComputer = CreateObject("Shell.LocalMachine")
    Set objEmail = CreateObject("CDO.Message")
    objEmail.From = "[email protected]"
    objEmail.To = "[email protected]"
    objEmail.Subject = "Backup Completed on Workstation name : " & objComputer.MachineName & " : Backup Completed " &" Date: " & Date() &" Time: " & Time()
    objEmail.TextBody = "Backup log attached for " & strComputerName
    objEmail.AddAttachment "F:\BACKUP.log"
    objEmail.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    objEmail.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
    "yourSMTP"
    objEmail.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
    objEmail.Configuration.Fields.Update
    objEmail.Send

  • #2
    Re: VBScript send from log NTBackup

    If the format of the log file is plain text then you can add this to the code:
    Code:
    Const ForReading = 1
    
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objTextFile = objFSO.OpenTextFile _
        ("F:\BACKUP.log", ForReading)
    strLogText = objTextFile.ReadAll
    objTextFile.Close  '!  do not forget this line
    And now you can add the variable strLogText to the objEmail.TextBody = line.
    http://www.paulsadowski.com/wsh/cdo.htm


    /Rems

    This posting is provided "AS IS" with no warranties, and confers no rights.

    __________________

    ** Remember to give credit where credit's due **
    and leave Reputation Points for meaningful posts

    Comment


    • #3
      Re: VBScript send from log NTBackup

      I try to type in the line don't have text in body


      objEmail.TextBody = strLogText


      ================================

      I try cannot


      Set objComputer = CreateObject("Shell.LocalMachine")
      Set objEmail = CreateObject("CDO.Message")
      Set objFSO = CreateObject("Scripting.FileSystemObject")
      Set objFile = objFSO.OpenTextFile("F:\BACKUP.log", 1)
      strResponses = objFile.ReadAll

      objEmail.From = "[email protected]"
      objEmail.To = "[email protected]"
      objEmail.Subject = "Backup Completed on Workstation name : " & objComputer.MachineName & " : Backup Completed " &" Date: " & Date() &" Time: " & Time()
      objEmail.TextBody = strResponses
      Last edited by momaydopod; 15th January 2014, 05:35.

      Comment


      • #4
        Re: VBScript send from log NTBackup

        Originally posted by momaydopod View Post
        I try to type in the line don't have text in body


        objEmail.TextBody = strLogText


        ================================

        I try cannot
        Code:
        Set objComputer = CreateObject("Shell.LocalMachine")
        Set objEmail = CreateObject("CDO.Message")
        Set objFSO = CreateObject("Scripting.FileSystemObject")
        Set objFile = objFSO.OpenTextFile("F:\BACKUP.log", 1)
        strResponses = objFile.ReadAll : objFile.Close '<-- [edit]
        objEmail.From = "[email protected]"
        objEmail.To = "[email protected]"
        objEmail.Subject = "Backup Completed on Workstation name : " & objComputer.MachineName & " : Backup Completed " &" Date: " & Date() &" Time: " & Time()
        objEmail.TextBody = strResponses
        I am missing the statement,
        objTextFile.Close
        You should add this in the script (see the inserted red colored text above).
        (you may have to restart the computer just in case - the log file could currently be locked because of the missing line objTextFile.Close in your script. A restart will end the file.open process that was started by the script, the log file will unlock again).

        And!, are you sure the log file contains just plain text and is ANSI encoded?

        /Rems
        Last edited by Rems; 15th January 2014, 21:13.

        This posting is provided "AS IS" with no warranties, and confers no rights.

        __________________

        ** Remember to give credit where credit's due **
        and leave Reputation Points for meaningful posts

        Comment


        • #5
          Re: VBScript send from log NTBackup

          Log copy from NTbackup log . OK log from NTBackup is ANSI encoded not plain text ,

          If i try to test delete contens in F:\BACKUP.LOG and type in word . It can write word to in body email




          Set objComputer = CreateObject("Shell.LocalMachine")
          Set objEmail = CreateObject("CDO.Message")
          Set objFSO = CreateObject("Scripting.FileSystemObject")
          Set objFile = objFSO.OpenTextFile("F:\BACKUP.log", 1, True, -1)
          strResponses = objFile.ReadAll
          objFile.Close
          objEmail.From = "your email"
          objEmail.To = "youemail"
          objEmail.Subject = "Backup Completed on Workstation name : " & objComputer.MachineName & " : Backup Completed " &" Date: " & Date() &" Time: " & Time()
          objEmail.TextBody = strResponses
          objEmail.AddAttachment "F:\BACKUP.log"
          objEmail.Configuration.Fields.Item _
          ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
          objEmail.Configuration.Fields.Item _
          ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
          "MySMTP"
          objEmail.Configuration.Fields.Item _
          ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
          objEmail.Configuration.Fields.Update
          objEmail.Send
          IT's Work
          Last edited by momaydopod; 16th January 2014, 05:15.

          Comment


          • #6
            Re: VBScript send from log NTBackup

            when i copy scipt to run another server have error popup
            Attached Files

            Comment


            • #7
              Re: VBScript send from log NTBackup

              Originally posted by momaydopod View Post
              when i copy scipt to run another server have error popup
              It appears the 'BACKUP.LOG' file that exist on the other server is empty.
              Why did you have added the parameters , True, -1 to the OpenTextFile statement in the script? This causing the script to create an empty file 'BACKUP.LOG' if there was no such file found in 'F:\'.

              What happened mostlikely is that on the other server there was no 'BACKUP.LOG' file. Therefor the script has created an empty file, becasues you added the parameter telling the script to create the file. Additionally the empty file is then raising the error.


              Leave the 3rd parameter (True) empty (or change it to False) so the script will not create the file if it does not yet exist.
              Set objFile = objFSO.OpenTextFile("F:\BACKUP.log", 1, , -1) . Because the backup job should create the log file and not the script.

              Remove the empty 'BACKUP.LOG' that was created by the script.

              The 4th parameter is the 'format' argument. It can have any of the following values:
              -2 (Opens the file using the system default), -1 (Opens the file as Unicode), 0 (Opens the file as ASCII). If the last parameter is omitted, the file is opened as ASCII


              If your script is tested and ready for use you can add the line On Error Resume Next to the top of the script. Then the script will try not to show error popups and wait for user action. But in this testing stage do not yet add this line.


              /Rems
              Last edited by Rems; 16th January 2014, 08:46.

              This posting is provided "AS IS" with no warranties, and confers no rights.

              __________________

              ** Remember to give credit where credit's due **
              and leave Reputation Points for meaningful posts

              Comment


              • #8
                Re: VBScript send from log NTBackup

                Thank you for your support


                Originally posted by Rems View Post
                It appears the 'BACKUP.LOG' file that exist on the other server is empty.
                Why did you have added the parameters , True, -1 to the OpenTextFile statement in the script? This causing the script to create an empty file 'BACKUP.LOG' if there was no such file found in 'F:\'.

                What happened mostlikely is that on the other server there was no 'BACKUP.LOG' file. Therefor the script has created an empty file, becasues you added the parameter telling the script to create the file. Additionally the empty file is then raising the error.


                Leave the 3rd parameter (True) empty (or change it to False) so the script will not create the file if it does not yet exist.
                Set objFile = objFSO.OpenTextFile("F:\BACKUP.log", 1, , -1) . Because the backup job should create the log file and not the script.

                Remove the empty 'BACKUP.LOG' that was created by the script.

                The 4th parameter is the 'format' argument. It can have any of the following values:
                -2 (Opens the file using the system default), -1 (Opens the file as Unicode), 0 (Opens the file as ASCII). If the last parameter is omitted, the file is opened as ASCII


                If your script is tested and ready for use you can add the line On Error Resume Next to the top of the script. Then the script will try not to show error popups and wait for user action. But in this testing stage do not yet add this line.


                /Rems

                Comment

                Working...
                X