![]() |
|
#1
|
|||
|
|||
How to implement the task by C languageOne log file named log.txt is generated every hour as below:
Display status detail. LPUTTIME(15.38.39) The field LPUTTIME means last data put time. Then i need to compare current time with value of LPUTTIME, mail script would be called to send mail alert if current time is larger than LPUTTIME 2 hours. How to implement the task by C? Thanks, Case |
|
#2
|
|||
|
|||
Re: How to implement the task by C languageI think it would be helpful to provide a little more description.
Please read the Guidelines for some suggestions on GOOD posting to the forum. - What OS? Shall we assume Linux? - Do you mean YOU want an alert message if system mail has new message? - Do you want to CALL a shell script for alert or generate from a function in your program? - What is your level of experience? Can YOU presently do this in a shell script? - How about an outline of how YOU think this might be accomplished in C? - etc. Howard; |
|
#3
|
|||
|
|||
Re: How to implement the task by C language1. Windows 2003 server.
2. The point is that I want to monitor one application that generates that log. 3. I prefer C than Windows scripts, e.g. VBscripts,etc. Thanks, Case |
|
#4
|
|||
|
|||
Re: How to implement the task by C languageYou mean the application already generates the log which has several line entries, the last of which would be a line like: LPUTTIME(15.38.39) ?
or that it generates a file with that being the only line? If it already creates the log then you need to first read that line eh? So do you know any C? Have a compiler set to go? Howard; |
|
#5
|
|||
|
|||
Re: How to implement the task by C language1.Yes, the application generates the log which has several line entries per hour, the log file shown as below:
5724-H72 (C) Copyright IBM Corp. 1994, 2004. ALL RIGHTS RESERVED. CURDEPTH(0) LPUTTIME(15.29.26) No commands have a syntax error. 2. How to pick-up time value behind LPUTTIME after fopen? 3. Can difftime be used to compare current time with that time value? Thanks, Case |
|
#6
|
||||
|
||||
Re: How to implement the task by C languagehello there.
Assuming that the log file is a txt file, would it be possible for you to write a C program that reads the relevant part in that file....ie the last 9 characters before the EOF..and then reformats it to remove the dots and the last bracket so that we have all numbers like for instance u can write a prog that reformats 15.29.26) to 152926(plain numbers..ie an array of chars perhaps) then compare this with another file which contains the system time which has again been reformated into the above format. I dunno much about the windows equivalent. Bt right now what comes to my freind is the unix diff command which has a lot of options to compare two ascii files. I wonder how to invoke unix commands under a C file and use the values/outputs from such commands in the C program..hmm..interesting..if anyone could enlighten us with the quirks of doing such a thing..id be grateful!! Theres a function called ctime which returns the time in 'human readable' format. Convert this string into the format that ur log file uses by discarding and re-ordering the characters. One could then easily use various string comparison techniques to check which one of them is the 'bigger' string thus enabling you to tell which is the bigger time value Do u want to do the comparison all the time..i mean is this program supposed to be running all the time..like a monitoring service of some kind?? __________________
Hope to hear from you guys! -------------------------------------------------- Best Regards, Aijaz Baig. |
|
#7
|
|||
|
|||
Re: How to implement the task by C languageFinally some info. but still sketchy... Your first post said .log is generated each hour.
Can we assume it is an updated log containing xxx lines of the the previous .log? or does it contain entries for ONLY that hour and you have several .log files... (yuk) I would start by making a samp.log file with different times to practice working with like: CPP / C++ / C Code:
CPP / C++ / C Code:
Which direction do you think makes sense? Howard; |
|
#8
|
|||
|
|||
Re: How to implement the task by C languageHi Howard,
Thanks for your frame work. I've been coding on main functions. Thanks again. Case |
|
#9
|
|||
|
|||
Re: How to implement the task by C languageQuote:
Don't be afraid to give a yell back if you get stumped. That's how we all learn. Include the code you have so far with any specific questions. It's a fun project, I've learned a lot in getting something working. I wound up taking the 'compare integer' approach (have not even needed string.h) and seem to be getting by ok with just these three functions: CPP / C++ / C Code:
I guess I could include my 'wordy' output, without giving too much away, from which you can see the flow and get an idea of how I decided to do the task. Code:
Presumably you would really only need to find the last time as it would be the latest, but I wanted to see if I could read further back into the file. Next would be HowTo call another program (like your mail alert) which I have no idea how to do yet. Child process? Good luck and have fun, I will, Howard; Last edited by Howard_L : 25-Jul-2007 at 00:54.
|
Recent GIDBlog
Meeting the local Iraqis by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| List of programming related questions | juvenile386 | Miscellaneous Programming Forum | 4 | 05-Jul-2007 07:49 |
| Looking for Advice: Would C++ be a good language to make this prototype product? | toastertester | C++ Forum | 3 | 25-Mar-2007 03:46 |
| Looking for opinions | crystalattice | Miscellaneous Programming Forum | 6 | 27-Sep-2006 21:02 |
| which language ? | onauc | C++ Forum | 2 | 19-Nov-2004 02:53 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The