From: Pankaj on 12 Jan 2010 15:11 Greetings, I have a file with following format Task1 01/12/2010 14:14:04 Task2 01/12/2010 14:00:07 Task3 01/12/2010 14:00:42 I am currently trying to achieve that if the time (last column) for any of the above task is more than 2 hours (as compared to current timing), then we need to get notified. Can anyone advise how to go about it. I am currently using ksh TIA
From: Ed Morton on 12 Jan 2010 15:54 On Jan 12, 2:11 pm, Pankaj <harpreet.n...(a)gmail.com> wrote: > Greetings, > > I have a file with following format > > Task1 01/12/2010 14:14:04 > Task2 01/12/2010 14:00:07 > Task3 01/12/2010 14:00:42 > > I am currently trying to achieve that if the time (last column) for > any of the above task is more than 2 hours (as compared to current > timing), then we need to get notified. > > Can anyone advise how to go about it. I am currently using ksh > > TIA This will print the number of hours difference and the task name for each line in your input file: gawk '{split($0,t,/[ /:]+/); print (systime() - mktime(t[4]" "t[2]" "t[3]" "t[5]" "t[6]" "t[7])) / 3600, $1}' file Ed.
From: Pankaj on 12 Jan 2010 16:08 On Jan 12, 3:54 pm, Ed Morton <mortons...(a)gmail.com> wrote: > On Jan 12, 2:11 pm, Pankaj <harpreet.n...(a)gmail.com> wrote: > > > Greetings, > > > I have a file with following format > > > Task1 01/12/2010 14:14:04 > > Task2 01/12/2010 14:00:07 > > Task3 01/12/2010 14:00:42 > > > I am currently trying to achieve that if the time (last column) for > > any of the above task is more than 2 hours (as compared to current > > timing), then we need to get notified. > > > Can anyone advise how to go about it. I am currently using ksh > > > TIA > > This will print the number of hours difference and the task name for > each line in your input file: > > gawk '{split($0,t,/[ /:]+/); > print (systime() - mktime(t[4]" "t[2]" "t[3]" "t[5]" "t[6]" "t[7])) / > 3600, $1}' file > > Ed. Thanks Ed but it seems I do not have gawk in sh or ksh here. I get following error gawk: not found Any alternate way to go about it.
From: Ed Morton on 12 Jan 2010 22:23 On 1/12/2010 3:08 PM, Pankaj wrote: > On Jan 12, 3:54 pm, Ed Morton<mortons...(a)gmail.com> wrote: >> On Jan 12, 2:11 pm, Pankaj<harpreet.n...(a)gmail.com> wrote: >> >>> Greetings, >> >>> I have a file with following format >> >>> Task1 01/12/2010 14:14:04 >>> Task2 01/12/2010 14:00:07 >>> Task3 01/12/2010 14:00:42 >> >>> I am currently trying to achieve that if the time (last column) for >>> any of the above task is more than 2 hours (as compared to current >>> timing), then we need to get notified. >> >>> Can anyone advise how to go about it. I am currently using ksh >> >>> TIA >> >> This will print the number of hours difference and the task name for >> each line in your input file: >> >> gawk '{split($0,t,/[ /:]+/); >> print (systime() - mktime(t[4]" "t[2]" "t[3]" "t[5]" "t[6]" "t[7])) / >> 3600, $1}' file >> >> Ed. > > Thanks Ed but it seems I do not have gawk in sh or ksh here. I get > following error > > gawk: not found > > Any alternate way to go about it. Just install gawk (http://www.gnu.org/software/gawk/), you'll thank yourself later... Ed.
From: Icarus Sparry on 12 Jan 2010 23:36 On Tue, 12 Jan 2010 21:23:45 -0600, Ed Morton wrote: > On 1/12/2010 3:08 PM, Pankaj wrote: >> On Jan 12, 3:54 pm, Ed Morton<mortons...(a)gmail.com> wrote: >>> On Jan 12, 2:11 pm, Pankaj<harpreet.n...(a)gmail.com> wrote: >>> >>>> Greetings, >>> >>>> I have a file with following format >>> >>>> Task1 01/12/2010 14:14:04 >>>> Task2 01/12/2010 14:00:07 >>>> Task3 01/12/2010 14:00:42 >>> >>>> I am currently trying to achieve that if the time (last column) for >>>> any of the above task is more than 2 hours (as compared to current >>>> timing), then we need to get notified. >>> >>>> Can anyone advise how to go about it. I am currently using ksh >>> >>>> TIA >>> >>> This will print the number of hours difference and the task name for >>> each line in your input file: >>> >>> gawk '{split($0,t,/[ /:]+/); >>> print (systime() - mktime(t[4]" "t[2]" "t[3]" "t[5]" "t[6]" "t[7])) / >>> 3600, $1}' file >>> >>> Ed. >> >> Thanks Ed but it seems I do not have gawk in sh or ksh here. I get >> following error >> >> gawk: not found >> >> Any alternate way to go about it. > > Just install gawk (http://www.gnu.org/software/gawk/), you'll thank > yourself later... > > Ed. If you are using a reasonably recent ksh93, then you can ignore Ed's advice as ksh93 can do it with builtin commands. The key is to note that printf "%(%#)T" now will give you the time in seconds since the epoch, and you can substitute any reasonable phrase for "now", like "last monday". So something like while read task day time do integer age=$(printf "%(%#)T-%(%#)T" "$day $time" now) if ((age > 2*3600)) then printf "%s is %d seconds old\n" "$task" $age fi done should do it.
|
Next
|
Last
Pages: 1 2 Prev: absg Next: zsh or ksh glob for directories and symlinks to directories |