The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Compare date from db2 table to yesterday's Unix system date sasaliasim Shell Programming and Scripting 9 3 Days Ago 08:37 PM
Changing Creation Date to a Prespecified Date of a File In Unix monkfan UNIX for Dummies Questions & Answers 4 11-28-2006 04:15 AM
A newbie with a problem in A date Script adija Shell Programming and Scripting 4 09-18-2006 05:22 AM
UNIX newbie NEWBIE question! Hanamachi UNIX for Dummies Questions & Answers 3 09-14-2006 07:23 AM
Newbie convert date ksh britney Shell Programming and Scripting 3 03-15-2006 07:55 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 01-14-2008
Registered User
 

Join Date: Jan 2008
Posts: 1
Please help - newbie (date)

Hi
I need help to write a script to do following:
Sample Input file1:
07-01-08 08:48:07:982 INFO [main] ....
07-01-08 08:49:07:982 DETAIL .....
07-01-08 08:50:14:982 INFO [main] .....
07-01-08 08:51:23:982 DETAIL .....
07-01-08 08:52:57:982 INFO [main] .....
07-01-08 08:53:01:982 DETAIL .....
07-01-09 01:53:01:982 DETAIL .....
07-01-10 16:00:00:000 INFO [main] .....

take the last date that contains 'DETAIL' word and then compare it with current time. If the difference is more than 30 minutes, then print 'Need Detail'


I can do it on the command line using:
grep DETAIL file1

and so far, i can convert the time to minutes using awk:
function to_sec(time){
split(time,a,":")
return (a[1]*60)+a[2]
}
{
print $2
request = to_sec($2)
currentTime = to_sec(date -s)
if ((currentTime - request) > 30)
{ print 'Need Detail' }
}

I am a newbie with script.. the above is totally not working.

Please help.
Thank you very much.
Reply With Quote
Forum Sponsor
  #2  
Old 01-15-2008
Registered User
 

Join Date: Jul 2007
Posts: 76
from the given input file...the below part of the script works as you desired.

lastdate=`date --date="$(grep "DETAIL" lastdate | tail -1 | cut -c 1-17)" +%s`
currdate=`date +%s`
diff=$(($currdate-$lastdate))
if [ $diff -gt "1800" ]
then
echo "It has been more than 30 mins, Need Details!"
fi


-ilan
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 07:11 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0