Sponsored Content
Top Forums Shell Programming and Scripting Grep last 30 minutes log only Post 302858715 by learnbash on Tuesday 1st of October 2013 07:05:09 AM
Old 10-01-2013
RedHat Grep last 30 minutes log only

I have below command, which i use for checking last two hours log file, but i want to check 30 minutes log and discard old log, only match current time with last 30 minutes. Command i am using. This below attach log file format is for this week, but sometime it got change in time of log, so i need to search on time base not on format base.

Code:
sed -n "/^$(date --date='2 hours ago' '+%b %d %H:')\\|^$(date --date='1 hours ago' '+%b %d %H:')/p"  logfile.txt

Attached File is for review.

Code:
Sep 29 03:21:02 server1 
Sep 29 03:31:02 server1 
Sep 29 04:21:02 server1 
Sep 29 04:31:02 server1 
Sep 29 05:21:02 server1 
Sep 29 05:31:02 server1 
Sep 29 06:21:02 server1 
Sep 29 06:31:02 server1 
Sep 29 13:21:02 server1 
Sep 29 13:31:02 server1 
Sep 29 14:21:02 server1 
Sep 29 14:31:02 server1 
Sep 29 15:21:02 server1 
Sep 29 15:31:02 server1 
Sep 29 16:21:02 server1 
Sep 29 16:31:02 server1 
Sep 29 17:21:02 server1 
Sep 29 17:31:02 server1 
Sep 30 03:21:02 server1 
Sep 30 03:31:02 server1 
Sep 30 04:21:02 server1 
Sep 30 04:31:02 server1 
Sep 30 05:21:02 server1 
Sep 30 05:31:02 server1 
Sep 30 06:21:02 server1 
Sep 30 06:31:02 server1 
Sep 30 13:21:02 server1 
Sep 30 13:31:02 server1 
Sep 30 14:21:02 server1 
Sep 30 14:31:02 server1 
Sep 30 15:21:02 server1 
Sep 30 15:31:02 server1 
Sep 30 16:21:02 server1 
Sep 30 16:31:02 server1 
Sep 30 17:21:02 server1 
Sep 30 17:31:02 server1
Oct  1 03:21:02 server1 
Oct  1 03:31:02 server1 
Oct  1 04:21:02 server1 
Oct  1 04:31:02 server1 
Oct  1 05:21:02 server1 
Oct  1 05:31:02 server1 
Oct  1 06:21:02 server1 
Oct  1 06:31:02 server1 
Oct  1 13:21:02 server1 
Oct  1 13:31:02 server1 
Oct  1 14:21:02 server1 
Oct  1 14:31:02 server1 
Oct  1 15:21:02 server1 
Oct  1 15:31:02 server1 
Oct  1 16:21:02 server1 
Oct  1 16:31:02 server1 
Oct  1 17:21:02 server1 
Oct  1 17:31:02 server1


Last edited by learnbash; 10-01-2013 at 08:31 AM.. Reason: add log file
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert minutes to hours, minutes, seconds

How would you convert lets say a 1000 minutes to hours, minutes, seconds (1 Reply)
Discussion started by: Vozx
1 Replies

2. Shell Programming and Scripting

Grepping the last 30 minutes of a log file...

I need to know if anyone can assist me on how to grab the last (we'll just say "x" minutes) of a log file. How do you tell the grep command without specifying an exact window of time? (So relative instead of absolute.) Thanks, Jon (2 Replies)
Discussion started by: jtelep
2 Replies

3. Shell Programming and Scripting

grep the time within given minutes

Mar 26 15:25:11 : jdoe : TTY=pts/2 ; PWD=/home/jdoe ; USER=root ; COMMAND=/usr/bin/su - Mar 26 15:28:52 : jdoe : 3 incorrect password attempts ; TTY=pts/2 ; PWD=/home/jdoe ; USER=root ; COMMAND=/usr/bin/su - Mar 25 12:23:07 : jdoe : TTY=pts/2 ; PWD=/home/jdoe ; USER=root ; ... (6 Replies)
Discussion started by: Daniel Gate
6 Replies

4. Shell Programming and Scripting

Script to grep for a string in log files generated in last 15 minutes.

Dear Guru's I've a requirment to grep for a string in series of log files that are getting generated almost every minute. I'm looking to schedule a script every 15 mountes,in order to check if the error string has been generated in any of the log files generated in last 15 minutes. Please... (3 Replies)
Discussion started by: rajivatnova
3 Replies

5. Shell Programming and Scripting

Move all .log except those generated in the last 5 minutes

RHEL 5.8 In the directory /u03/pkms/app_logs I have several hundreds of log files as shown below. $ pwd /u03/pkms/app_logs $ ls -alrt *.log | tail -50 -rw-r----- 1 oracle dba 9439232 May 4 13:57 mvtpcem_1_722892404_94157.log -rw-r----- 1 oracle dba 9227264 May 4 13:57... (8 Replies)
Discussion started by: kraljic
8 Replies

6. Shell Programming and Scripting

Log File Creations for every 60 minutes

Hi All, Below script will make a copy of the existing log file with the then timestamp details. I am looking to create a copy of the existing log file for every 60 minutes and when the file limit reaches to 5, the 6th copy should overwrite the first backedup file which means all the time it... (3 Replies)
Discussion started by: Upendra Bestha
3 Replies

7. Shell Programming and Scripting

Run this grep every 10 minutes and do something based on the output

OS : Red Hat Linux 6.4 Shell : Bash We have a file called status.txt which will have only 1 line. The content will be the string "Processing" for most of the day. # cat status.txt Processing #I want to write a shell script (notify.sh) which will be executing a grep every 10 minutes . ... (7 Replies)
Discussion started by: kraljic
7 Replies

8. Shell Programming and Scripting

Grep last 2 minutes log only

I have newbie, which i use for checking last one hours log file, but i want to check 2 minutes log and discard old log, only match current time with last 2 minutes. Ex log. 2018-07-03 20:09:17 2018-07-03 20:05:17 2018-07-03 20:05:18 2018-07-03 20:05:20 2018-07-03 20:06:22 2018-07-03... (5 Replies)
Discussion started by: ooilinlove
5 Replies

9. UNIX for Beginners Questions & Answers

How to convert days hours minutes seconds to minutes?

Hi, please help with below time conversion to minutes. one column values: 2 minutes 16 seconds 420 msec 43 seconds 750 msec 0 days 3 hours 29 minutes 58 seconds 480 msec 11 seconds 150 msec I need output in minutes(total elapsed time in minutes) (2 Replies)
Discussion started by: ramu.badugula
2 Replies

10. Shell Programming and Scripting

Grep a log file for the last 5 minutes of contents every 5 minutes

Hi all, System Ubuntu 16.04.3 LTS i have the following log INFO 2019-02-07 15:13:31,099 module.py:700] default: "POST /join/8550614e-3e94-4fa5-9ab2-135eefa69c1b HTTP/1.0" 500 2042 INFO 2019-02-07 15:13:31,569 module.py:700] default: "POST /join/6cb9c452-dcb1-45f3-bcca-e33f5d450105... (15 Replies)
Discussion started by: charli1
15 Replies
WHO(1)							    BSD General Commands Manual 						    WHO(1)

NAME
who -- display who is on the system SYNOPSIS
who [-abHmqsTu] [am I] [file] DESCRIPTION
The who utility displays information about currently logged in users. By default, this includes the login name, tty name, date and time of login and remote hostname if not local. The options are as follows: -a Equivalent to -bTu, with the exception that output is not restricted to the time and date of the last system reboot. -b Write the time and date of the last system reboot. -H Write column headings above the output. -m Show information about the terminal attached to standard input only. -q ``Quick mode'': List the names and number of logged in users in columns. All other command line options are ignored. -s Show the name, line and time fields only. This is the default. -T Indicate whether each user is accepting messages. One of the following characters is written: + User is accepting messages. - User is not accepting messages. ? An error occurred. -u Show idle time for each user in hours and minutes as hh:mm, '.' if the user has been idle less than a minute, and ``old'' if the user has been idle more than 24 hours. am I Equivalent to -m. By default, who gathers information from the file /var/run/utx.active. An alternate file may be specified which is usually /var/log/utx.log (or /var/log/utx.log.[0-6] depending on site policy as utx.log can grow quite large and daily versions may or may not be kept around after compression by ac(8)). The utx.log file contains a record of every login, logout, crash, shutdown and date change since utx.log was last truncated or created. If /var/log/utx.log is being used as the file, the user name may be empty or one of the special characters '|', '}' and '~'. Logouts produce an output line without any user name. For more information on the special characters, see getutxent(3). ENVIRONMENT
The COLUMNS, LANG, LC_ALL and LC_TIME environment variables affect the execution of who as described in environ(7). FILES
/var/run/utx.active /var/log/utx.log /var/log/utx.log.[0-6] EXIT STATUS
The who utility exits 0 on success, and >0 if an error occurs. SEE ALSO
last(1), users(1), w(1), getutxent(3) STANDARDS
The who utility conforms to IEEE Std 1003.1-2001 (``POSIX.1''). HISTORY
A who command appeared in Version 1 AT&T UNIX. BSD
February 11, 2012 BSD
All times are GMT -4. The time now is 02:38 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy