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

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

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.

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
jnewton03
Asked:
jnewton03
1 Solution
 
etmendzCommented:
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
 
pratap_rCommented:
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
 
jnewton03Author Commented:
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
pratap_rCommented:
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
 
Razzie_Commented:
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
 
jnewton03Author Commented:
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
 
pratap_rCommented:
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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