Command to grep the service with in a timeframe


 
Thread Tools Search this Thread
Operating Systems Solaris Command to grep the service with in a timeframe
# 8  
Old 10-28-2015
Given your log file has date and time in the first two fields of every entry, try:
Code:
awk '/^2010-06-10.*Loadservice/ {CNT[substr($2, 1, 2)]++} END {for (c in CNT) print c, CNT [c]}' log.06102013.svr1

# 9  
Old 10-28-2015
Corona,

Here is the file info:

Code:
2010-06-10 00:00:35,222|B|stack|sys|||gprs|true|1|{http:///}LoadService|info
2010-06-10 00:00:35,333|B|stack|sys|||gprs|true|9|{http:///}LoadService|info
2010-06-10 01:00:00,333|B|stack|sys|||gprs|true|2|{http:///}LoadService|info

when I execute the script then it gives me '3'

Last edited by Corona688; 10-28-2015 at 05:44 PM..
# 10  
Old 10-28-2015
The first time in the entire thread "LoadService" has an upper case "S". That built in,
Code:
awk '/^2010-06-10.*LoadService/ {CNT[substr($2, 1, 2)]++} END {for (c in CNT) print c, CNT [c]}' file
00 2
01 1

This User Gave Thanks to RudiC For This Post:
# 11  
Old 10-28-2015
Thanks Rudy.
I am not that good at scripting, so can you explain me the script and out come?

00 2
01 1

I am getting something like this when I execute the awk command. so, does 00 means hours and 2 is the count?
# 12  
Old 10-28-2015
Yes, that's the hour and its count.
The awk looks for lines that contain the target date AND the search word "LoadService". If found, a counter array indexed by the hour (two digits from time string) is incremented. In the end, the result is printed.
# 13  
Old 10-28-2015
Quote:
Originally Posted by kriss.gv
Corona,

Here is the file info:

Code:
2010-06-10 00:00:35,222|B|stack|sys|||gprs|true|1|{http:///}LoadService|info
2010-06-10 00:00:35,333|B|stack|sys|||gprs|true|9|{http:///}LoadService|info
2010-06-10 01:00:00,333|B|stack|sys|||gprs|true|2|{http:///}LoadService|info

when I execute the script then it gives me '3'
The nice thing about dates in YYYY-MM-DD HH:MM:SS order is they compare alphabetically. An exact match is no longer necessary -- you can use >, >=, <, <= to compare the date and get logical answers. awk will take one or more files, too.

Code:
$ awk -F"|" '{ sub(/,.*/, "", $1) } ; ($1 >= S) && ($1 <= E) && /LoadService/ { L++ } END { print L+0 }' S="2010-06-10 00:00:00" E="2010-06-10 01:00:00" inputfile1 inputfile2

3

$

# 14  
Old 10-29-2015
Thanks much Corona
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Viewing a specific timeframe of a log file

Hi guys Done a bit of research online but can't seem to figure it out, is there anyway of grepping or using sed to view a specific time period of a log file. I am trying to view a log file for Saturday 22nd April between 08:00 - 12:00 I saw this command online and tried but doesn't seem to... (10 Replies)
Discussion started by: simpsa27
10 Replies

2. SuSE

Is this iostat pipe to sort service request command correct?

Hi, my os is SLES 10 from sort iostat as my output does not include rkB/s and wkB/s I probably have to adjust the key position, so is the following iostat pipe to sort service request command correct? oracle@vmc_stallite:~> iostat -x | sort -nrk11 sda 0.96 ... (4 Replies)
Discussion started by: jediwannabe
4 Replies

3. Red Hat

No reponse to 'service NFS start' command

Hello, I have a newly kickstarted RHEL 6.4 server that I'm trying to set-up as a kickstart server. I have done this before on other machines, but I am encountering some strange behaviour in this one. # service nfs status rpc.svcgssd is stopped rpc.mountd is stopped nfsd is stopped... (0 Replies)
Discussion started by: Chopstyx
0 Replies

4. Solaris

Logging out idle users after a certain timeframe

We recently underwent a security audit and have a new requirement to not allow users to stay logged on overnight. In order to place this policy into effect i need a way to check for idle users and log them off. Is there any good way to enforce this policy in Solaris 10 and make it work in such a... (11 Replies)
Discussion started by: goose25
11 Replies

5. Shell Programming and Scripting

Date within a timeframe 2 days ago

How could I using the following example, change it to show 2 days ago within the same time frame 0600 AM to 0600 AM let foo=`date "+(1%H-106)*60+1%M-100"` bar=foo+1440 find . -mmin +$foo -mmin -$bar | tr -s '/','-' '^' | cut -f2,3 -d"^" | tr -s '^' ' ' | Please use code tags (7 Replies)
Discussion started by: freddie999
7 Replies

6. Shell Programming and Scripting

print contents of any file within some timeframe

Hi, Is there anyway to print contents of any file ( say log files that grow automatically) within some timeframe ( comparing with current time), say print contents of the added in: 1) last 2 hr 2) last 45 min 3) last 3 hrs 47 min (3 Replies)
Discussion started by: fed.linuxgossip
3 Replies
Login or Register to Ask a Question