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
204 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 11

Expert Comment

by:pratap_r
Comment Utility
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_
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video discusses moving either the default database or any database to a new volume.

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now