[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Script and email log files

Posted on 2007-07-22
11
Medium Priority
?
559 Views
Last Modified: 2008-01-09
Hi Guys,
I am robo copying some files from 30 servers to another location and writing them to an appending log file that starts a new one each day.  The servers are Win2003.
I am copying from servers name mbox2003, mbox2004 etc ....
I want to have a report emailed to me each day that has a break of all the servers names and the whether the copy was a success or not.
Eg... Mbox2004  Success =  xx  Failed = xx
An example of the .txt log file is below:            
    2      \\mbox2003\c$\Program Files\NCR Aptra\Advance NDC\data\
          Newer                   135081      EJDATA.LOG
  0%   45%   90%  100%  
------------------------------------------------------------------------------
                Total    Copied   Skipped  Mismatch    FAILED    Extras
     Dirs :         1         0         1         0         0         0
    Files :         2         1         1         0         0         0
    Bytes :   338.1 k   131.9 k   206.1 k         0         0         0
    Times :   0:00:12   0:00:12                       0:00:00   0:00:00
    Speed :               11170 Bytes/sec.
    Speed :               0.639 MegaBytes/min.
    Ended : Wed Jul 18 17:10:41 2007
                         2      \\mbox2004\c$\Program Files\NCR Aptra\Advance NDC\data\
------------------------------------------------------------------------------
                Total    Copied   Skipped  Mismatch    FAILED    Extras
     Dirs :         1         0         1         0         0         0
    Files :         2         0         2         0         0         0
    Bytes :    2.69 m         0    2.69 m         0         0         0
    Times :   0:00:00   0:00:00                       0:00:00   0:00:00
    Ended : Wed Jul 18 17:10:45 2007
                         2      \\mbox2005\c$\Program Files\NCR Aptra\Advance NDC\data\
          Newer                   249911      EJDATA.LOG
  0%   24%   49%   73%   98%  100%  
------------------------------------------------------------------------------
                Total    Copied   Skipped  Mismatch    FAILED    Extras
     Dirs :         1         0         1         0         0         0
    Files :         2         1         1         0         0         0
    Bytes :   626.1 k   244.0 k   382.0 k         0         0         0
    Times :   0:00:26   0:00:25                       0:00:00   0:00:00
    Speed :                9670 Bytes/sec.
    Speed :               0.553 MegaBytes/min.


Any Ideas?
Chris
0
Comment
Question by:ISfish
  • 6
  • 5
11 Comments
 
LVL 65

Expert Comment

by:RobSampson
ID: 19545256
Hi, if you have a computer that has relay enabled for it, I have used a program called BMailer.exe and the following code:
'===============
Dim strMessageBody, strRecipient, strGateWay, strSender, strSubject, strBMailerCommand, objShell

strMessageBody = "The contents of the file could go here"
strRecipient = "username@domain.com"
strGateWay = "mailserver"
strSender = "admin@domain.com"
strSubject = "Report Email"

strBMailerCommand = "bmailer -s " & strGateWay& " -t " & strRecipient & " -f " & strSender & " -a """ & strSubject & """ -b """ & strMessageBody & """"

Set objShell = CreateObject("Wscript.Shell")
objShell.Run strBMailerCommand, 0, True
'=================

BMailer can be downloaded from here:
http://www.beyondlogic.org/solutions/cmdlinemail/cmdlinemail.htm

Regards,

Rob.
0
 

Author Comment

by:ISfish
ID: 19545311
Hi Rob,

Is there any way to get the contents from the log file?
That is, read through the log file get the numbers and pull it to s structured file. The email part it ok once I have this.

Cheers
Chris
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 19545330
Sure,
If you use
'===========
objFSO = CreateObject("Scripting.FileSystemObject")
Const intForReading = 1
Set objInputFile = objFSO.OpenTextFile("C:\Folder\File.txt", intForReading, False)
strMessageBody = objInputFile.ReadAll
objInputFile.Close
Set objInputFile = Nothing
Set objFSO = Nothing
'==============

Then, strMessageBody contains the entire text file, and should be able to be emailed.

If you want to filter the report file, you would have to use
objInputFile.ReadLine
instead of
objInputFile.ReadAll

and then perform some conditional tests to decide what to do with each line.

Basically, if you want that line, store it in strMessageBody, otherwise do nothing with it.

If you let me know which parts of the file you want, I can help you with that.

Regards,

Rob.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:ISfish
ID: 19555154
Hi Rob,

Thanks for the advice. I will try it tomorrow when I am at work.

There are 50 sets of results in the text file and I want to grab the below out of the results for each server.

mbox2001
------------------------------------------------------------------------------
                Total    Copied   Skipped  Mismatch    FAILED    Extras
     Dirs :         1         0         1         0         0         0
    Files :         2         1         1         0         0         0

mbox2002
------------------------------------------------------------------------------
                Total    Copied   Skipped  Mismatch    FAILED    Extras
     Dirs :         1         0         1         0         0         1
    Files :         2         1         1         0         0         0

Which is a break down of the result from 2 of the sets.

Is this possible?

Chris
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 19563073
Hi, here is the rest of the script that filters the contents of the file.  

You will need to change the file path in the line
objFSO.OpenTextFile("C:\Temp\Temp\Sample.txt", intForReading, False)

And also comment out the WScript.Quit when you are ready to test the bmailer.exe

Regards,

Rob.

'===================
Dim strMessageBody, strRecipient, strGateWay, strSender, strSubject, strBMailerCommand, objShell

' Get the contents of the text file
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const intForReading = 1
Set objInputFile = objFSO.OpenTextFile("C:\Temp\Temp\Sample.txt", intForReading, False)
strMessageBody = ""
While Not objInputFile.AtEndOfStream
      strLine = objInputFile.ReadLine
      If InStr(strLine, "\\") > 0 Then strMessageBody = strMessageBody & VbCrLf & Left(Right(strLine, Len(strLine) - InStr(strLine, "\\") - 1), InStr(Right(strLine, Len(strLine) - InStr(strLine, "\\") - 1), "\") - 1)
      If InStr(strLine, "-----------------") > 0 Then      strMessageBody = strMessageBody & VbCrLf & strLine
      If InStr(strLine, "Mismatch") > 0 Then      strMessageBody = strMessageBody & VbCrLf & strLine
      If InStr(strLine, "Dirs :") > 0 Then      strMessageBody = strMessageBody & VbCrLf & strLine
      If InStr(strLine, "Files :") > 0 Then      strMessageBody = strMessageBody & VbCrLf & strLine
Wend
objInputFile.Close
Set objInputFile = Nothing
Set objFSO = Nothing

MsgBox strMessageBody
WScript.Quit

strMessageBody = "The contents of the file could go here"
strRecipient = "username@domain.com"
strGateWay = "mailserver"
strSender = "admin@domain.com"
strSubject = "Report Email"

strBMailerCommand = "bmailer -s " & strGateWay& " -t " & strRecipient & " -f " & strSender & " -a """ & strSubject & """ -b """ & strMessageBody & """"

Set objShell = CreateObject("Wscript.Shell")
objShell.Run strBMailerCommand, 0, True
'=================
0
 

Author Comment

by:ISfish
ID: 19642901
Thanks for that.
What is the command to pipe it to a text file instead of it popping up on a screen

Cheers
Chris
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 19642928
Do you want to output strMessageBody to a text file?  Would you overwrite this file each time?  That is not required for the mailing to work, it is just there to show you what the body "will" be.  You can just comment out (or delete) the MsgBox strMessageBody and it will have no effect on the text sent in the mail.

Regards,

Rob.
0
 

Author Comment

by:ISfish
ID: 19707544
Hi Rob,
Yep I would like to write the output to a text file each day and send this file in an email. The output file will be overwritten each day.
I have install blat on the server as well and it is being used to send another text file. The admin that used to work with me wrote a jsscript to do what I want now but I am not sure how to alter or simplify it. I can copy and paste it here if you like?

Chris
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 19713548
OK, so to write the strMessageBody to a file, this will do it:
'===================
Dim strMessageBody, strRecipient, strGateWay, strSender, strSubject, strBMailerCommand, objShell

' Get the contents of the text file
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const intForReading = 1
Set objInputFile = objFSO.OpenTextFile("C:\Temp\Temp\Sample.txt", intForReading, False)
strMessageBody = ""
While Not objInputFile.AtEndOfStream
      strLine = objInputFile.ReadLine
      If InStr(strLine, "\\") > 0 Then strMessageBody = strMessageBody & VbCrLf & Left(Right(strLine, Len(strLine) - InStr(strLine, "\\") - 1), InStr(Right(strLine, Len(strLine) - InStr(strLine, "\\") - 1), "\") - 1)
      If InStr(strLine, "-----------------") > 0 Then      strMessageBody = strMessageBody & VbCrLf & strLine
      If InStr(strLine, "Mismatch") > 0 Then      strMessageBody = strMessageBody & VbCrLf & strLine
      If InStr(strLine, "Dirs :") > 0 Then      strMessageBody = strMessageBody & VbCrLf & strLine
      If InStr(strLine, "Files :") > 0 Then      strMessageBody = strMessageBody & VbCrLf & strLine
Wend
objInputFile.Close
Set objInputFile = Nothing
Set objOutputFile = objFSO.CreateTextFile("C:\Temp\Temp\MessageBody.txt", True)
objOutputFile.Write strMessageMessageBody
objOutputFile.Close
Set objOutputFile = Nothing
Set objFSO = Nothing

'MsgBox strMessageBody
'WScript.Quit

strMessageBody = "The contents of the file could go here"
strRecipient = "username@domain.com"
strGateWay = "mailserver"
strSender = "admin@domain.com"
strSubject = "Report Email"

strBMailerCommand = "bmailer -s " & strGateWay& " -t " & strRecipient & " -f " & strSender & " -a """ & strSubject & """ -b """ & strMessageBody & """"

Set objShell = CreateObject("Wscript.Shell")
objShell.Run strBMailerCommand, 0, True
'=================

So that gives you the body as a text file, which you could attach, although I'm not familiar with BLAT, so I will need the source code that at least creates the mail and sends it.....

Regards,

Rob.
0
 

Author Comment

by:ISfish
ID: 19713667
Thanks Rob,
I will give this a try
once blat is installed all you have to do is:
blat logcheck.txt -t customer@company.com -cc carboncopy@company.com -s "This is the subject"

Cheers
Chris
0
 
LVL 65

Accepted Solution

by:
RobSampson earned 2000 total points
ID: 19713734
OK, In that case, you should be able to use:
'===========
strMessageBody = "c:\temp\temp\MessageBody.txt"
strRecipient = "customer@company.com"
strCC = "carboncopy@company.com"
strSubject = "This is the subject"

strBlatCommand = "blat """ & strMessageBody & """ -t " & strRecipient & " -cc " & strCC & " -s """ & strSubject & """
Set objShell = CreateObject("Wscript.Shell")
objShell.Run strBlatCommand, 0, True
'===========

in place of the code below the 'WScript.Quit line.
Also, I forgot to mention, please change the file paths in
Set objOutputFile = objFSO.CreateTextFile("C:\Temp\Temp\MessageBody.txt", True)
and
strBlatCommand = "blat """ & strMessageBody & """ -t " & strRecipient & " -cc " & strCC & " -s """ & strSubject & """

to suit.....

Regards,

Rob.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question