Extracting a Time Span from Syslog Messages File


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Extracting a Time Span from Syslog Messages File
# 1  
Old 12-09-2010
Extracting a Time Span from Syslog Messages File

Hi all,

I need your help to explain how I can extract a time span from the syslog messages file on a Solaris 10 system.
Here is an example extract of the syslog messages:
Code:
Dec  4 11:51:38 hajap141-0107.nls.jlrint.com 267938: Dec  4 11:51:36: %DOT11-6-DISASSOC: Interface Dot11Radio0, Deauthenticating Station 000f.f84e.0d00 Reason: Previous authentication no longer valid
Dec  4 11:51:43 solap149-b48h.nls.jlrint.com 440904: Dec  4 11:51:42: %DOT11-6-ASSOC: Interface Dot11Radio0, Station  0040.96b4.f18b Reassociated KEY_MGMT[NONE]
Dec  4 11:51:43 solap162-b48h.nls.jlrint.com 660076: Dec  4 11:51:42: %DOT11-6-ROAMED: Station 0040.96b4.f18b Roamed to 0023.ac5a.df30

I would like help to extract messages from "Dec 4" from 11:00 to 11:15.

Regards, Wynford

Last edited by jim mcnamara; 12-10-2010 at 05:27 PM..
# 2  
Old 12-10-2010
Do you have GNU date?

For starters, go to the FAQ here and look into the datecalc script that Perderabo wrote called 'Date Arithmetic'.

The primary data element used throught UNIX for time keeping and file times is the epoch second, the number of seconds since Jan 1 1970. Convert a desired start date/time to epoch seconds, convert a desired stop date/time to epoch seconds. Then for each record you can pick what you want.

In your case there is a shortcut, but if choose to extend the time by much you will find it will not work - why the talk about epoch seconds above.
Code:
dmesg | awk -v { /^Dec  4/ {  tmp=substr($3,1,2) substr($3,4,2); 
           if(tmp>="1100" && tmp <="1115") {print $0} }  0 '

You may not be using dmesg, use your method instead. just keep the awk segment.

Last edited by jim mcnamara; 12-10-2010 at 05:44 PM.. Reason: oops - $1 changed to $3
# 3  
Old 12-10-2010
If this is a one time search, and you're going to throw the code away:

Code:
grep "Dec  4 11:[0-1][0-5]" filename

This User Gave Thanks to purdym For This Post:
# 4  
Old 12-10-2010
or cryptic awk:
Code:
nawk -F'[: ]'  '/Dec 4/ && $3==11 && $4 < 16 {print} 0'  filename

# 5  
Old 12-13-2010
Thanks Jim and Purdym,

I decided to use;

grep "Dec 4 11:[0-1][0-5]" filename
as this was easier and only a one-off.

Thanks for all your help Smilie

Regards, Wynford
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Total size utilizes by the files older than a time span

Through find command I identified the files older that 1 year. I need the overall size utilizes by these 1 year older files. Please share me the command to identify it .Thanks Please post in an adequate technical forum! (3 Replies)
Discussion started by: Sang
3 Replies

2. Shell Programming and Scripting

Extracting log files based on date and time.

Hi All, i have some log files generated in a folder daily with the format abc.def.20130306.100001 ghi.jkl.20130306.100203 abc.def.20130305.100001 ghi.jkl.20130305.100203 the format is the date followed by time . all i want is to get the files that are generated for todays... (3 Replies)
Discussion started by: mahesh300182
3 Replies

3. UNIX for Dummies Questions & Answers

Extracting substring between pattern only one time

Hello ifconfig return : eth0 Link encap:Ethernet HWaddr 11:24:1D:C1:99:BA inet addr:192.168.0.1 Bcast:192.168.0.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:37307 errors:0 dropped:0 overruns:0 frame:0 ... (2 Replies)
Discussion started by: jcdole
2 Replies

4. Shell Programming and Scripting

need to grep contents of a file within specific time span. regex i am using is not working

Hi , I am trying to extract contents of a file between specified time stamp. but it does not seem to work. i am trying to extract output of /var/adm/messages between 15:00:00 to 15:23:59 . i have tried two regex the first one seems to kind of work. it displays some output. the second one is... (13 Replies)
Discussion started by: chidori
13 Replies

5. Shell Programming and Scripting

select the lines in between some time span

Hi Everyone ! i want to take all the lines from a file that falls in between some date... and every line in a file has a time stamp.. ---some text---- 01/Jan/2010 ---- some other text ---- ---some text---- 10/Jan/2010 ---- some other text ---- ---some text---- 20/Dec/2010 ---- some... (3 Replies)
Discussion started by: me_newbie
3 Replies

6. Shell Programming and Scripting

extracting data from file using time stamp

Hi Guys ! is it possible to extract lines from a file which satisfy a time contraint for example program should consider two boundaries one current time and second the user define time and then extract all those line which fall into that specified time lets say 10 (user define time) and 12... (5 Replies)
Discussion started by: ourned
5 Replies

7. Shell Programming and Scripting

Extracting date & time from file name

Hi, I am having a file name as exp_bkp_tables_18_Oct_2010_10_50_28.dmp which is used for import the records. Now, I want to print the output using the selected file name as below : Table records will get restored as on date 18-Oct-2010 and time 10:50:28 How it can be done ? With... (5 Replies)
Discussion started by: milink
5 Replies

8. Shell Programming and Scripting

Extracting lines in file based on time

Hi, anyone has any ideas on how do we extract lines from a file with format similiar to this: (based on current time) Jun 18 00:16:50 .......... ............. ............ Jun 18 00:17:59 .......... ............. ............ Jun 18 01:17:20 .......... ............. ............ Jun 18... (5 Replies)
Discussion started by: faelric
5 Replies

9. Shell Programming and Scripting

Extracting time from Crontab

Hi, I am a beginner in shell scripting but I have a task to complete where I have to extract the time of script execution in human format so anyone can run the script and understand what script is running when in simple format. Let me illustrate what I mean: Two scripts in crontab, for this... (4 Replies)
Discussion started by: harjitsingh
4 Replies

10. Shell Programming and Scripting

Extracting date-time from file.

I have the following file and need to extract date and time part for each record. Pl. could anyone provide an shell script which could be used to do it. Here is the file: /rgrdev/pdsud2/unx/agc/src/agcmst: /rgrsrc/pdspms/unx/agc/src/s.agcmst.for agcmst.for 420.20 8/4/07 18:30:53 ... (7 Replies)
Discussion started by: skumar11
7 Replies
Login or Register to Ask a Question