Solved

I need to write a C# program that will search a certain log file on about 100 machines for certain text and output that to a table or listbox or some other output.

Posted on 2004-10-11
7
206 Views
Last Modified: 2010-04-15
I need to write a loop that will check a certain log file on about 100 machines and then in a list box print out the machine name, the last instance of the word "backup" in the log and the date following "date=" in the log.

Here is an example of the log:

<![LOG[Retrieved local Management Point from AD: BACKUP]LOG]!><time="13:16:03.645+300" date="10-11-2004" component="LocationServices" context="" type="1" thread="320" file="lsad.cpp:2514">

So what I need is:

LOOP:
Check the log file at \\machine1\C$\Windows\System32\Log\backup.log all the way through
\\machine99\C$\Windows\System32\Log\backup.log

Find last instance of the word "BACKUP" and "date=" in the log and put that into a list box or some other form of output. If "BACKUP" doesn't exist just print "No" in the listbox next to that machine name.

Hope this makes sense.

After that, I'd like to make changes to the program to allow it to interact with Active Directory and check the c:\windows\system32\Logs\backup.log on every machine in the OU that I choose.  Is that possible?

Thanks in advance,

Jake
0
Comment
Question by:jnewton03
7 Comments
 
LVL 6

Expert Comment

by:etmendz
ID: 12284846
This is usually a billable request. An entire project maybe with a deadline and, optionally, a project manager. You might also want to hire a software architect and another developer. You might also want to include your systems/infrastructure architect to offer expertise on how to make this possible on your network. Optionally, get a technical writer for the documents and a tester to complete the team.

Just kidding...

But if you can show what you've done so far then maybe we can focus on what exactly is the problem... so far, I think the problem is that you don't have the confidence to start this yourself...
0
 
LVL 11

Expert Comment

by:pratap_r
ID: 12286023
sure its possible.. and heres the code... :-)

      string mcbase="machine";
      for(int i=1; i < 100; i++)
      {
            TextReader tr=new StreamReader(@"\\"+mcbase+i+@"\c$\Windows\System32\Log\backup.log");
            string str=tr.ReadToEnd();
            Regex r=new Regex("BACKUP.*date=\"([^\"]*)\"",RegexOptions.RightToLeft);
            Match m=r.Match(str);
            if(m.Length==0)
                  MessageBox.Show("No");
            else
                  MessageBox.Show(m.Groups[1].ToString());
      }

it does a regex match agains the words backup and date="" so you might want to change that a bit to make it match better... i have tested it against the input you gave so it should work i guess. and you might want to put in some error handling also..

next for AD... post on your requirements.. sounds like fun :-)

btw, my billing rate will be 140$ per hour.. heh :-) ... just kidding

Enjoy!
Pratap
0
 

Author Comment

by:jnewton03
ID: 12288229
Thanks for the help.  The Regular Expression is always returning "No."  I'm really bad with Regular Expressions, so are you sure that's the correct format for the log I showed above?

Also, for the AD part, I'd like to show a Tree where I can click on whichever OU I want (the Domain name is IOWA) and have the program check that log on every machine in that OU and output to a table with the following columns: (Machine Name, If it has the log with the word Backup in it (yes or no), and the date).

Eventually I'd like this to be a web application so I may end up re-writing it in ASP.Net.
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 11

Expert Comment

by:pratap_r
ID: 12289386
yes its exactly the same log.. i copied the log line and created a file on my drive and checked it.. can you attach a few more lines.. probably its something else

for the AD part it shouldnt be a problem... just put the above code in a function which accepts the machine name as parameter and you are good to go.. just call the function whenever you click the treeview node...

Pratap
0
 
LVL 8

Expert Comment

by:Razzie_
ID: 12290166
Unless this is for some rotten test database, you have plain SQL in your log file including columns and table names. I don't know your enviroment the application is running, but it is a bad idea to post things like this on the net since hackers love that.
0
 

Author Comment

by:jnewton03
ID: 12290560
Sorry bout that.  That was the wrong log file anyways.  Here is my log file (last few entries):

<![LOG[Current AD site of machine is Default-First-Site-Name]LOG]!><time="18:07:56.880+300" date="09-30-2004" component="LocationServices" context="" type="1" thread="388" file="lsad.cpp:215">
<![LOG[Retrieved local Management Point from AD: BACKUP]LOG]!><time="18:07:56.880+300" date="09-30-2004" component="LocationServices" context="" type="1" thread="388" file="lsad.cpp:2514">
<![LOG[Current AD site of machine is Default-First-Site-Name]LOG]!><time="18:07:56.970+300" date="09-30-2004" component="LocationServices" context="" type="1" thread="388" file="lsad.cpp:215">

Should the regular expression you showed still work?

Also, someone please let me know if this is still dangerous to post (I'm bad with SQL)


Thanks again!
Jake
0
 
LVL 11

Accepted Solution

by:
pratap_r earned 500 total points
ID: 12295050
it works fine.. this is the output i get in the message box.. exactly what you are looking for..
09-30-2004

i mean i dont see any compromising information in what you have posted so you should be safe :-)

Enjoy!
Pratap
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Server Error 11 58
use of unassigned local variable 'id' 6 38
MediaHelp 4 23
VB: Convert 2 dates to specific format 24 48
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

770 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