GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 20-Jul-2007, 23:56
newonea newonea is offline
New Member
 
Join Date: Jul 2007
Posts: 4
newonea is on a distinguished road

How to implement the task by C language


One 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  
Old 21-Jul-2007, 08:19
Howard_L Howard_L is offline
Regular Member
 
Join Date: Apr 2007
Location: Maryland/PA, USA
Posts: 470
Howard_L has a spectacular aura aboutHoward_L has a spectacular aura about

Re: How to implement the task by C language


I 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  
Old 21-Jul-2007, 19:46
newonea newonea is offline
New Member
 
Join Date: Jul 2007
Posts: 4
newonea is on a distinguished road

Re: How to implement the task by C language


1. 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  
Old 21-Jul-2007, 20:28
Howard_L Howard_L is offline
Regular Member
 
Join Date: Apr 2007
Location: Maryland/PA, USA
Posts: 470
Howard_L has a spectacular aura aboutHoward_L has a spectacular aura about

Re: How to implement the task by C language


You 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  
Old 23-Jul-2007, 07:24
newonea newonea is offline
New Member
 
Join Date: Jul 2007
Posts: 4
newonea is on a distinguished road

Re: How to implement the task by C language


1.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  
Old 23-Jul-2007, 08:21
aijazbaig1's Avatar
aijazbaig1 aijazbaig1 is offline
Member
 
Join Date: May 2006
Location: Sweden
Posts: 134
aijazbaig1 will become famous soon enough

Re: How to implement the task by C language


hello 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  
Old 23-Jul-2007, 11:46
Howard_L Howard_L is offline
Regular Member
 
Join Date: Apr 2007
Location: Maryland/PA, USA
Posts: 470
Howard_L has a spectacular aura aboutHoward_L has a spectacular aura about

Re: How to implement the task by C language


Finally 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:
/* samp.log */
5724-H72 (C) Copyright IBM Corp. 1994, 2004. ALL RIGHTS RESERVED.

CURDEPTH(0) LPUTTIME(15.29.26)
No commands have a syntax error.

5724-H72 (C) Copyright IBM Corp. 1994, 2004. ALL RIGHTS RESERVED.

CURDEPTH(0) LPUTTIME(16.29.26)
No commands have a syntax error.

5724-H72 (C) Copyright IBM Corp. 1994, 2004. ALL RIGHTS RESERVED.

CURDEPTH(0) LPUTTIME(17.29.26)
No commands have a syntax error.
Then begin to phase in the 'to do' list , starting with something like this:
CPP / C++ / C Code:
/* mailrun.c */
#include <stdio.h>
#include <string.h>   /* you will need this for strcmp() etc */
#include <time.h>     /* you will need this for getting present time */
#define infile "samp.log"

FILE *fp;

int main(void)
{
  fp = fopen(infile, "rb");
  if(fp == NULL) {
    printf("      *** problem opening '%s'...  exiting... \n", infile);
    return 1;
  }
  else {
    printf("  '%s' opened for reading \n", infile);
    /* do stuff , but what? */
    /* for starters a function to get present time into a format to search with:
       eg: a string 15.29.26   ( but how would you compare to within 2 hours? )
       eg: an int 152926       ( but then in the search loop you'd have to
                                 convert each xx.xx.xx to an int to compare  
    decisions, decisions....  */

    /* then take that time to a search function */

    printf("  '%s' closed \n", infile);
    fclose(fp);
  }
  return 0;
}
There are probably many different ways to go about these things.
Which direction do you think makes sense?
Howard;
  #8  
Old 24-Jul-2007, 23:13
newonea newonea is offline
New Member
 
Join Date: Jul 2007
Posts: 4
newonea is on a distinguished road

Re: How to implement the task by C language


Hi Howard,

Thanks for your frame work.

I've been coding on main functions.

Thanks again.

Case
  #9  
Old 24-Jul-2007, 23:37
Howard_L Howard_L is offline
Regular Member
 
Join Date: Apr 2007
Location: Maryland/PA, USA
Posts: 470
Howard_L has a spectacular aura aboutHoward_L has a spectacular aura about

Re: How to implement the task by C language


Quote:
I've been coding on main functions.
Good. I was afraid we had lost you. Have you gotten the your present time yet?

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:
/* function declarations */
int get_time(void);                        /* returns present time as an hhmmss integer */
int search_for_time(FILE *fp, int time );  /* returns hhmmss int of found time or 0     */
int timestr_to_int(char timestr[]);        /* converts hh.mm.ss string to hhmmss int    */
In search_for_time() I search the file from the end using fseek() one getc() at a time until I find a target character set ( I chose 'ME(' ) and then getc() forward 8 for the date string. pretty neat... it really works!
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:
D:\C\gidforum\newonea> mailrun_1x1.exe 'samp.log' opened for reading In main(). The file's time will have this format '15.29.26' timestamp: 2007 07 25 01 14 32 Back in main() from get_time(): The time is: 11432. I'm going for the convert 15.29.26 to int route. In filetime_to_int, timestr= 15.29.26 Back in main() from filetime_to_int() test: filetime= 152926 Ok that looks useable, so now we go on to the file search. I'd think starting from the end of file would make sense. In search_for_time() from timestr_to_int(): time= 11432 Setting time +240000 for midnight thru 2AM adjustment: time= 251432 .rorre xatnys a evah sdnammoc oN )62.92.50(EME(05.29.26 ...Dude!, we got a string: >05.29.26<. Now call timestr_to_int(): In filetime_to_int, timestr= 05.29.26 i= 47 filetime=52926 NO Match, time(251432) - filetime(52926) = 198506 6ITTUPL )0(HTPEDRUC .DEVRESER STHGIR LLA .4002 ,4991 .proC M(NO Match2)BI thgirypoC )C( 27H-4275 .rorre xatnys a evah sdnammoc oN )62.92.80(EME(08.29.26 ...Dude!, we got a string: >08.29.26<. Now call timestr_to_int(): In filetime_to_int, timestr= 08.29.26 i= 184 filetime=82926 NO Match, time(251432) - filetime(82926) = 168506 6ITTUPL )0(HTPEDRUC .DEVRESER STHGIR LLA .4002 ,4991 .proC M(NO Match2)BI thgirypoC )C( 27H-4275 .rorre xatnys a evah sdnammoc oN )62.92.32(EME(23.29.26 ...Dude!, we got a string: >23.29.26<. Now call timestr_to_int(): In filetime_to_int, timestr= 23.29.26 i= 321 filetime=232926 Match Found! time(251432) - filetime(232926) = 18506 Back in main(): Time within two hours of 11432 found: 232926 'samp.log' closed
I used the samp.log (previously posted above) and changed the times around.
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 GIDBlogMeeting the local Iraqis by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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

All times are GMT -6. The time now is 06:45.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.