Calculate response time from log

I have a running log file (jboss_server.log) which rotates at midnight . I need to constantly check and calculate the time for each thread and alert if it doesnt complete within 60 minute. For example my log file has following printed .

I want to run a script in cron every 30 minutes and look for last " Thread:" and check the date time stamp against current time and send me an email if it is longer than 60 minutes. The app has 15 threads.

What OS - do you have gnu date?

Here is a good start for you but you will need to add code
to handle crossing mid-might. Hope this helps.

#!/bin/ksh
calc_time()
{
set -x
start_time=$1
end_time=$2
start_hh=$(echo $start_time | $AWK -F':' ' { print $1 } ')
start_mm=$(echo $start_time | $AWK -F':' ' { print $2 } ')
start_ss=$(echo $start_time | $AWK -F':' ' { print $3 } ')
 
end_hh=$(echo $end_time | $AWK -F':' ' { print $1 } ')
end_mm=$(echo $end_time | $AWK -F':' ' { print $2 } ')
end_ss=$(echo $end_time | $AWK -F':' ' { print $3 } ')
 
startsecs=`expr $start_hh \* 3600`
startsecs=`expr $startsecs + $start_mm \* 60`
startsecs=`expr $startsecs + $start_ss`
endsecs=`expr $end_hh \* 3600`
endsecs=`expr $endsecs + $end_mm \* 60`
endsecs=`expr $endsecs + $end_ss`
echo `expr $endsecs - $startsecs`
}
set -x
AWK=nawk
stime=`date +"%H:%M:%S"`
sleep 3
etime=`date +"%H:%M:%S"`
num_secs=$(calc_time $stime $etime )
echo "$stime $etime $num_secs"

---------- Post updated at 04:33 PM ---------- Previous update was at 04:19 PM ----------

Here is a solution in "C" if you like. It requires less tinkering but will
give you what you need.

#include <stdio.h>
#include <time.h>
static char *now();
static int csstrptime(char *, char *, struct tm * );
main()
{
char *format1="YYYYMMDDHHMMSS";
char *format2="YYYYMMDD";
struct tm tm1, tm2;
time_t secs1, secs2;
char *d1= now();
char *d2="20030118";
memset (&tm1, 0, sizeof tm1);
memset (&tm2, 0, sizeof tm2);
if (csstrptime(d1, format1, &tm1) != 0)
{
printf ("csstrptime failed. Date = %s format = %s", d1, format1 );
return (1);
}
if (csstrptime(d2, format2, &tm2) != 0)
{
printf ("csstrptime failed. Date = %s format = %s", d1, format2 );
return (1);
}
secs1 = mktime(&tm1);
secs2 = mktime(&tm2);
if (secs2 > secs1 )
printf ("Secs = %ld\n", secs2-secs1);
else
printf ("Secs = %ld\n", secs1-secs2);
}
 
 
 
/*****************************************************************************
**
** Name csstrptime()
**
** Purpose: This function converts the character string pointed to by buf to
** values, which are stored in the tm structure pointed to by tm,
** using the format specified by format.
**
** There is a system call strptime(), which works this emulates but
** there are known bugs in that function. For example, when parsing 
** the format'YYYYMMDDHHMMSS' on Solaris it does not work correctly.
** The format must be 'YYYY MM DD HH MM SS'.
**
** In addition, strptime() does not appear to be avialable on NT.
** Syntax:
** static int csstrptime(const char *buf, const char *format, struct tm *tm);
**
** Parameters:
** buf IN Date to converted
**
** format IN Format of DATE (YYYYMMDDHHMMSS or YYYYMMDD)
**
** tm OUT time structure
** int tm_sec; seconds after the minute - [0, 61]
** int tm_min; minutes after the hour - [0, 59]
** int tm_hour; hour since midnight - [0, 23]
** int tm_mday; day of the month - [1, 31] 
** int tm_mon; months since January - [0, 11]
** int tm_year; years since 1900 
** int tm_wday; days since Sunday - [0, 6]
** int tm_yday; days since January 1 - [0, 365]
** int tm_isdst; daylight savings time flag.
**
** Returns: Returns zero for success one if there is an error.
** 
*****************************************************************************/ 
 
static int
csstrptime(char *buf, char *format, struct tm *tm )
{
int year=0, month=0, day=0, hour=0, minute=0, second=0;
 
tm->tm_isdst = 0;
if (!strcmp(format, "YYYYMMDDHHMMSS") &&
(sscanf(buf, "%4d%2d%2d%2d%2d%2d",
&year, &month, &day, &hour, &minute, &second) == 6))
{
tm->tm_year = year - 1900;
tm->tm_mon = month - 1;
tm->tm_mday = day;
tm->tm_hour = hour;
tm->tm_min = minute;
tm->tm_sec = second;
}
else if (!strcmp(format, "YYYYMMDD") &&
(sscanf(buf, "%4d%2d%2d", &year, &month, &day) == 3))
{
tm->tm_year = year - 1900;
tm->tm_mon = month - 1;
tm->tm_mday = day;
/* Set the time to midnight since not time was given */
tm->tm_hour = 0;
tm->tm_min = 0;
tm->tm_sec = 0;
}
else
return (1);
return(0);
}
 
 
 
/*****************************************************************************
**
** Name now()
**
** Syntax: static char *now();
**
** Parameters: NONE
** Returns: Returns the the current date and time in YYYYMMDDHHMMSS format.
** 
*****************************************************************************/ 
/*
** This function returns the current date and time in YYYYMMDDHHMMSS format
*/
static char *
now()
{
static char current_time[20];
time_t clock;
 
clock = time((time_t)0);
(void)strftime(current_time, sizeof(current_time), "%Y%m%d%H%M%S", localtime(&clock));
return (current_time);
}