Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 580
  • Last Modified:

A Script to get the remote machines log file and edit and send a mail or copy to specified UNC location

Hi,

A Script to get the remote machines log file and edit and send a mail or copy to specified UNC location
In this location
C:\windows\system32\logfiles\W3SVC100
I have the log files
Everyday it generated a new file like : ex071010.log
So a way that a script first copys todays file to the UNC location edits it leaves just the below mwentioned text.

2007-10-10 05:49:55 W3SVC100 IN-EX-CL02 129.120.120.120 POLL /exchange/Jacob.Vijaykumar/Inbox - 80 DEVELOPMENT\JacobV 129.120.120.120 Exchange-Server-Frontend-Proxy/6.5+Mozilla/4.0+(compatible;+MSIE+7.0;+Windows+NT+5.2;+.NET+CLR+1.1.4322;+.NET+CLR+2.0.50727;+.NET+CLR+3.0.04506.30) 207 0 0

Need to get these details deleting all the other content.The main log should not be disturbed.
DEVELOPMENT\JacobV 129.120.120.120

Regards
Sharath
0
bsharath
Asked:
bsharath
  • 6
  • 5
1 Solution
 
ghostdog74Commented:
how is the log file like? possible to provide a sample.
0
 
bsharathAuthor Commented:
Th log file is named as todays date.

In it i have 100's of such data.

2007-10-10 05:49:55 W3SVC100 IN-EX-CL02 129.120.120.120 POLL /exchange/Jacob.Vijaykumar/Inbox - 80 DEVELOPMENT\JacobV 129.120.120.120 Exchange-Server-Frontend-Proxy/6.5+Mozilla/4.0+(compatible;+MSIE+7.0;+Windows+NT+5.2;+.NET+CLR+1.1.4322;+.NET+CLR+2.0.50727;+.NET+CLR+3.0.04506.30) 207 0 0
0
 
ghostdog74Commented:
yes, so what is the search criteria ? DEVELOPMENT\JacobV ??  129.120.120.120 ?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
bsharathAuthor Commented:
From all the logs i just need the Development\name and ip address.
0
 
ghostdog74Commented:
you can use this vbscript to get the required string DEVELOPMENT\user IP

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set wshArgs = WScript.Arguments
myFile = wshArgs.Item(0)
Set objFile = objFSO.OpenTextFile(myFile,1)
Do Until objFile.AtEndOfStream      
      line =objFile.ReadLine
      strLine = Split(line)
      For i=LBound(strLine) To UBound(strLine)
            If InStr(1,strLine(i),"DEVELOPMENT") >0 Then
                  WScript.Echo strLine(i) , strLine(i+1)
            End If             
      Next      
Loop

usage: save it as myscript.vbs and in your batch file:

@echo off
for /f "tokens=*" %%a in ('C:\windows\system32\logfiles\W3SVC100\*log') do (
      echo %%a
      cscript /nologo myscript.vbs %%a >> outfile
      copy outfile UNC_path
)

something like that...

0
 
bsharathAuthor Commented:
I get this

When i run vbs file

---------------------------
Windows Script Host
---------------------------
Script:      C:\myscript.vbs
Line:      3
Char:      1
Error:      Subscript out of range
Code:      800A0009
Source:       Microsoft VBScript runtime error

---------------------------
OK  
---------------------------

I created 2 files 1 vbs and 1 bat file when i run the bat file nothing happens.When i run the vbs i get the above error.
0
 
ghostdog74Commented:
you have to pass in an argument.. please look at the sample batch i posted. Its supposed to pass in the log file to the vbscript...if you run the vbscript manually, then it should look something like this:

c:\> cscript /nologo myscript.vbs C:\windows\system32\logfiles\W3SVC100\ex071010.log
0
 
bsharathAuthor Commented:
Haa got it...
But i cannot specify the date can the script find todays date and get the info.

Can i even get this part
2007-10-10 05:49:55
Date and time in the output
0
 
ghostdog74Commented:
yes you can

please look at this part :

....
   strLine = Split(line)
      For i=LBound(strLine) To UBound(strLine)
            If InStr(1,strLine(i),"DEVELOPMENT") >0 Then
                  WScript.Echo strLine(i) , strLine(i+1)
            End If            
      Next      
....

each line is splitted into fields using space as delimiter, so strLine now is an array of elements. The date
and time is strLine(0) and strLine(1) respectively. I leave it to you to echo it out? should be easy...try it :-)
0
 
bsharathAuthor Commented:
Should it look like this...

If InStr(1,strLine(i),"DEVELOPMENT") >0 Then
                  WScript.Echo strLine(i) , strLine(i+1)
                  WScript.Echo strLine(0) and strLine(1)
            End If  
0
 
ghostdog74Commented:
that would put the date and time on a different line...
try this:

If InStr(1,strLine(i),"DEVELOPMENT") >0 Then
   .....
   wscript.Echo strLine(i) , strLine(i+1) , strLine(0)  , strLine(1)
     .....
end if

all you need to do is to run the script and see the output for yourself.
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now