VBScript send from log NTBackup

Home Forums Scripting Windows Script Host VBScript send from log NTBackup

This topic contains 7 replies, has 3 voices, and was last updated by Avatar manikandan_p 5 years, 8 months ago.

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • Avatar
    momaydopod
    Member
    #163028

    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 ?

    Quote:
    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
    Rems
    Rems
    Moderator
    #228396

    Re: VBScript send from log NTBackup

    If the format of the log file is plain text then you can add this to the 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
    [/CODE]
    And now you can add the variable [COLOR=”red”]strLogText[/COLOR] to the [COLOR=”green”]objEmail.TextBody = [/COLOR] line.
    [url]http://www.paulsadowski.com/wsh/cdo.htm[/url]

    /Rems[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
    [/CODE]
    And now you can add the variable strLogText to the objEmail.TextBody = line.
    http://www.paulsadowski.com/wsh/cdo.htm

    /Rems

    Avatar
    manikandan_p
    Member
    #382492

    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

    Rems
    Rems
    Moderator
    #228399

    Re: VBScript send from log NTBackup

    momaydopod;280415 wrote:
    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[SIZE=”3″] [I][COLOR=RED][B]: objFile.Close[/SIZE] ‘< — [edit][/B][/COLOR][/I]
    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

    Avatar
    manikandan_p
    Member
    #382493

    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

    Quote:
    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

    Avatar
    manikandan_p
    Member
    #382494

    Re: VBScript send from log NTBackup

    when i copy scipt to run another server have error popup :-?

    Rems
    Rems
    Moderator
    #228400

    Re: VBScript send from log NTBackup

    momaydopod;280452 wrote:
    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

    Avatar
    manikandan_p
    Member
    #382495

    Re: VBScript send from log NTBackup

    Thank you for your support

    Rems;280454 wrote:
    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

Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.