Need logs 5 mins old


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need logs 5 mins old
# 1  
Old 05-04-2016
Need logs 5 mins old

I need 5 mins old logs to be dumped into a a new file.

The date formats in the two log files are

Quote:
1. Mar 10, 2016 1:51:09 PM CST
2. 2016-05-02 07:22:14
Can you suggect for both formats ?
Code:
bash-3.2$ uname -a
SunOS myserver 5.10 Generic_150400-26 sun4v sparc sun4v

---------- Post updated 05-04-16 at 12:24 AM ---------- Previous update was 05-03-16 at 07:54 PM ----------

This is what i do for 10 mins of logs

set the crontab to work every 9,19,29,39,49,59 mins

10minlogs.sh
Code:
LOGDATE=`date '+%Y-%m-%d %k:%M' | cut -c1-15`
sleep 60
grep "$LOGDATE" /tmp/logs/server.out>every10min.out

Can some help me with 5 mins of logging for both or even one of the date formats in this or any other fashion ?

Last edited by mohtashims; 05-04-2016 at 11:22 AM..
# 2  
Old 05-04-2016
Format #2 can be compared with awk, like

Code:
awk -v DATE="5-minutes-ago-timestamp" '$0 >= DATE' inputfile

Getting the 5 minutes ago date on Solaris can be difficult, on Linux you would use GNU date, on Sun you can try using my perl script

So:

Code:
awk -v DATE=$(./gdate.pl +"%Y-%m-%d %H:%M:%S" -d "now - 5 minutes") '$0 >= DATE' logfile

I'm not sure how to deal with format #1, informally-formatted dates like that are a pain to compare.

Last edited by Corona688; 05-04-2016 at 12:30 PM..
# 3  
Old 05-04-2016
Hi.

For systems new enough:
Code:
OS, ker|rel, machine: SunOS, 5.11, i86pc
Distribution        : Oracle Solaris 11.3 X86
gdate date (GNU coreutils) 8.16

Best wishes ... cheers, drl
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Grep last 5 mins from logs

Hi, system date format Thu Jun 13 12:55:18 EDT 2019 My log date format 09.148.192.60 - - "GET /akamai/sureroute-test-object.html HTTP/1.1" 404 231 can someone please help me, how to get last 5mins of logs please ? I need the command Please wrap your samples/codes in CODE TAGS,... (3 Replies)
Discussion started by: scazed
3 Replies

2. Shell Programming and Scripting

If I ran perl script again,old logs should move with today date and new logs should generate.

Appreciate help for the below issue. Im using below code.....I dont want to attach the logs when I ran the perl twice...I just want to take backup with today date and generate new logs...What I need to do for the below scirpt.............. 1)if logs exist it should move the logs with extention... (1 Reply)
Discussion started by: Sanjeev G
1 Replies

3. Shell Programming and Scripting

How to check if there is a file in the last 10 mins?

I have a script that runs every hour from the crontab (see the settings of the crontab below) (15 mins past the hour) 15 * * * * /home/usr/usr1/ProvAll This script saves two files in the following format now=`/bin/date '+%Y%m%d.%H%M%S'` file1.$now (for example) file1.20140722.031502... (12 Replies)
Discussion started by: knijjar
12 Replies

4. Shell Programming and Scripting

tail for 15 mins

Hi, I want to write a script which will tail a particular file for 15 mins and then sleep for 10 mins and again tail for 15 mins. This cycle will go on for a limited period of time. How can i ensure that tail command will run for 15 mins before calling sleep command Thanks (6 Replies)
Discussion started by: @bhi
6 Replies

5. Shell Programming and Scripting

invoke this command after every 10 mins

Hi, I have an command which find the files modified within last 3 days and then after selecting the files from the location it make the tar format and send it to the specified destination ...now I want that this task to be automative ..that is it should happen after every 5 minutes ..plz guide me... (5 Replies)
Discussion started by: Neera
5 Replies

6. Shell Programming and Scripting

Retrieve logs generated in last 10 mins from a log file using 'grep' command

HI All, I have a log file where the logs will be in the format as given below: 2011-05-25 02:32:51 INFO PROCESS STARTING 2011-05-25 02:32:52 INFO PROCESS STARTED . . . I want to retrieve only the logs which are less than 5 mins older than current time using grep... (3 Replies)
Discussion started by: rvhg16
3 Replies

7. UNIX for Advanced & Expert Users

How to test the script for every 30 mins

Test job to make sure pwctest service is up Test script which can run every 30 mins to make sure pwctest is available. a) If Error , script should send email to Tech. plz help me out for this script i'm waiting for reply.....plz (7 Replies)
Discussion started by: ksrivani
7 Replies

8. UNIX for Advanced & Expert Users

getting time mins ago

Hi I trying to get 5 mins ago time using below command echo `date +%R -d "1 min ago"` but this is giving only current time. Please help (6 Replies)
Discussion started by: cka
6 Replies

9. Shell Programming and Scripting

Grep yesterday logs from weblogic logs

Hi, I am trying to write a script which would go search and get the info from the logs based on yesterday timestamp and write yesterday logs in new file. The log file format is as follows: """"""""""""""""""""""""""... (3 Replies)
Discussion started by: harish.parker
3 Replies

10. UNIX for Dummies Questions & Answers

files created within last 10 mins

Any simple 1 liners to check a directory to see if a file was created within the last 10 mins? (5 Replies)
Discussion started by: frustrated1
5 Replies
Login or Register to Ask a Question