![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#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. |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
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 |
|||
| Google The UNIX and Linux Forums |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|