Sponsored Content
Top Forums Shell Programming and Scripting Getting the last hour from a log. Post 302492099 by Jotne on Saturday 29th of January 2011 06:47:41 PM
Old 01-29-2011
Getting the last hour from a log.

I have a log like this:
Code:
Jan 26 13:59:41 server2 ntpdate[634]: step time server 91.189.94.4 offset 0.065456 sec
Jan 26 13:59:41 server2 ntpd[715]: ntpd 4.2.4p8@1.1612-o Fri Aug  6 22:49:54 UTC 2010 (1)
Jan 26 13:59:41 server2 ntpd[729]: precision = 1.000 usec
Jan 26 13:59:41 server2 ntpd[729]: ntp_io: estimated max descriptors: 1024, initial socket boundary: 16
Jan 26 13:59:41 server2 ntpd[729]: Listening on interface #0 wildcard, 0.0.0.0#123 Disabled
Jan 26 13:59:41 server2 ntpd[729]: Listening on interface #1 wildcard, ::#123 Disabled
Jan 26 13:59:41 server2 ntpd[729]: bind() fd 18, family AF_INET6, port 123, scope 2fails: Cannot assign requested address
Jan 26 13:59:41 server2 ntpd[729]: unable to create socket on eth0 (2) for 2002:54ca:8b5a:1:209:6bff:fe85:6ab7#123
Jan 26 13:59:41 server2 ntpd[729]: failed to initialize interface for address 2002:54ca:8b5a:1:209:6bff:fe85:6ab7
Jan 26 13:59:41 server2 ntpd[729]: Listening on interface #3 eth0, fe80::209:6bff:fe85:6ab7#123 Enabled

I need to get the last hour of log and have made a script for it.
It works, but I need some help simplify it.
I do not need NOW, getting to end of file is good enough, but how to do it.
Can I get all in one line (not use $FROM and $NOW)
Maybe speed it up some. Log size is 2270000 lines long and growing. Takes around 3 seconds to complete.

So I tried this
#!/bin/sh
FROM=$(date +%b" "%d" "%H:%M:%S -d "-1 hour")
NOW=$(date +%b" "%d" "%H:%M:%S)
cat /var/log/daemon.log | awk '$0>=from&&$0<=to' from="$FROM" to="$NOW" | wc -l

Last edited by Jotne; 01-29-2011 at 07:56 PM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

1 Hour less

set DAY=`date +%y%m%d` set H=`date +%H` set M=`date +%M` mailx -s "$H-Mydata" myemail@mail.com<mydata I am looking to set the current hour to have 1 hour less in the subject header: For example: let's say the system time is 8 I want to have "7-Mydata" not "8-Mydata" Can some1... (6 Replies)
Discussion started by: bobo
6 Replies

2. UNIX for Dummies Questions & Answers

an hour less in 24 hour system

My program: __________________________________ #!/bin/ksh DAY=`date +%y%m%d` H=`date +%H` M=`date +%M` day=`date +%m/%d/%y` let h=$H-1 echo DAY $DAY echo H $H echo M $M echo day $day echo h $h _____________________________________ My result: (3 Replies)
Discussion started by: bobo
3 Replies

3. Shell Programming and Scripting

Calculate total of log by hour

Hi, Just wondering, is there anyway I can get the total of logs generated by hours ? Let say I have these logs, Sep 23 04:48:43 hsbcufs: NOTICE: realloccg /: file system full Sep 23 04:48:47 hsbcufs: NOTICE: alloc: /: file system full Sep 23 04:48:51 hsbcufs: NOTICE: realloccg /: file... (14 Replies)
Discussion started by: dehetoxic
14 Replies

4. Shell Programming and Scripting

How to convert 24 hour time to 12 hour timing?

Hi friends, I want to convert 24 hour timing to 12 hour please help me... my data file looks like this.. 13-Nov-2011 13:27:36 15.32044 72.68502 13-Nov-2011 12:08:31 15.31291 72.69807 16-Nov-2011 01:16:54 15.30844 72.74028 15-Nov-2011 20:09:25 15.35096 ... (13 Replies)
Discussion started by: nex_asp
13 Replies

5. Shell Programming and Scripting

How to get next hour?

Hi guys I want any script to get me next hour For example Nexthour.sh 2013022823 It get me result 2013030100 Thanks a lot , I'm using Solaris 10 (5 Replies)
Discussion started by: teefa
5 Replies

6. Shell Programming and Scripting

Write Log per hour

Hi, the follow can add the day time to my Log file My_Log_$(date +%F).log can I add the hour to the end of my log file then my log file will looks like My_Log_07-24:(:confused: (3 Replies)
Discussion started by: Hscript
3 Replies

7. Shell Programming and Scripting

Pattern from a log within last hour

I want to extract a pattern from a log file within last hour. I am doing grep "pattern" filename | tail -1 It gives the last latest pattern but not within last hour. and if the pattern found in last hour, output success or else failure. (3 Replies)
Discussion started by: santosh2626
3 Replies

8. Shell Programming and Scripting

Pick the last one hour lines from log matching this pattern.

Hello please help me on this, pick the last one hour lines from the log, which have the prefix time format like this. log message log message i tried to do grep, but that failed. my code grep '(date +)' log_file_path This checking only the current time stamp. How to get the log... (16 Replies)
Discussion started by: santosh2626
16 Replies

9. Shell Programming and Scripting

Grep in a log file within a time range (hour)

Hi, im trying to write a grep script that returns me the last inputs added in the last hour in the log file. Literally i have nothing yet but: grep 'Line im looking for' LOGFILE.log | tail -1 this only gives me the last input, but no necessarily from the last hour. Help Please. (4 Replies)
Discussion started by: blacksteel1988
4 Replies

10. UNIX for Advanced & Expert Users

Want to get average value for each hour

I want to get CPU average value only (not required user CPU & memory) with each hours on individual date. The sample output is below | | | User |Memory| User | Date | Time |CPU %|CPU % | % |Mem % | 03/02/2015|00:00:00| 24.56| 20.66| 89.75| 63.48|... (13 Replies)
Discussion started by: Saravanan_0074
13 Replies
ntp-wait(1)							   User Commands						       ntp-wait(1)

NAME
ntp-wait - Wait for ntpd to stabilize the system clock SYNOPSIS
ntp-wait [-flags] [-flag [value]] [--option-name[[=| ]value]] All arguments must be options. DESCRIPTION
ntp-wait will send at most num-tries queries to ntpd(8), sleeping for secs-between-tries after each status return that says ntpd(8) has not yet produced a synchronized and stable system clock. ntp-wait will do this quietly, unless the -v flag is provided. This can be useful at boot time, to delay the boot sequence until after ntpd -g has set the time. OPTIONS
-n number, --tries=number Number of times to check ntpd. This option takes an integer number as its argument. The default number for this option is: 100 The maximum number of times we will check ntpd to see if it has been able to synchronize and stabilize the system clock. -s secs-between-tries, --sleep=secs-between-tries How long to sleep between tries. This option takes an integer number as its argument. The default secs-between-tries for this option is: 6 We will sleep for secs-between-tries after each query of ntpd that returns "the time is not yet stable". -v, --verbose Be verbose. By default, ntp-wait is silent. With this option, ntp-wait will provide status information. -?, --help Display usage information and exit. -!, --more-help Pass the extended usage information through a pager. -v [{v|c|n --version [{v|c|n}]}] Output version of program and exit. The default mode is `v', a simple version. The `c' mode will print copyright information and `n' will print the full copyright notice. EXIT STATUS
One of the following exit values will be returned: 0 (EXIT_SUCCESS) Successful program execution. 1 (EXIT_FAILURE) The operation failed or the command syntax was not valid. 70 (EX_SOFTWARE) libopts had an internal operational error. Please report it to autogen-users@lists.sourceforge.net. Thank you. AUTHORS
Harlan Stenn NOTES
This document corresponds to version 4.2.8p13 of NTP. This manual page was AutoGen-erated from the ntp-wait option definitions. ntp (4.2.8p13) 20 Feb 2019 ntp-wait(1)
All times are GMT -4. The time now is 01:47 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy