Last 24 hours of a log file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Last 24 hours of a log file
# 1  
Old 07-09-2008
Last 24 hours of a log file

I'm looking to pull the last 24 hours of a log file.

Here's what I've got so far:
yesterday=$(TZ=$TZ+24 date +"%b %e %H:%M")
today=$(date +"%b %e %H:%M")
echo $yesterday $today

grep -E "^$yesterday|^$today" /var/adm/syslog/syslog.log

But that pulls everything from $yesterday from 12:01am instead of 24 hrs prior to the current date and time.

Thoughts?

Thanks...
# 2  
Old 07-09-2008
Bug

Quote:
Originally Posted by Bert
I'm looking to pull the last 24 hours of a log file.

Here's what I've got so far:
yesterday=$(TZ=$TZ+24 date +"%b %e %H:%M")
today=$(date +"%b %e %H:%M")
echo $yesterday $today

grep -E "^$yesterday|^$today" /var/adm/syslog/syslog.log

But that pulls everything from $yesterday from 12:01am instead of 24 hrs prior to the current date and time.

Thoughts?

Thanks...
Try this :
sed -n "/^${yesterday}/,/^${today}/ p" /var/adm/syslog/syslog.log
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

How to get ALL update dates and hours of a file?

Hello, I have a question please, How could I get ALL update dates and hours of a file ? For example: I modified a file on 09/04/2014 at 7:am for the first time. Then, I modified again the same file on 09/04/2014 at 9 am and finally, I modified the same file again on 10/04/2014 at... (3 Replies)
Discussion started by: nurinolo
3 Replies

2. Shell Programming and Scripting

Parsing log file for last 2 hours

I want to parse a log file which i am grepping root user connection but is showing whole day and previous day detail as well. First i want to see last 2 hours log file then after that i want to search particular string. Lets suppose right now its 5:00PM, So i want to see the log of 3:00PM to... (6 Replies)
Discussion started by: learnbash
6 Replies

3. Shell Programming and Scripting

Log search and mail it if the log is updated before 24 hours from the current time

Hi , We have around 22 logs , each has different entries. I have to automate this using shell script. The ideas which am sharing is given below 1) We use only TAIL -100 <location and name of the log> Command to check the logs. 2) We want to check whether the log was updated before 24... (13 Replies)
Discussion started by: Kalaihari
13 Replies

4. Shell Programming and Scripting

sed 2 hours in log

Hi, I want grep a log between two hours cat server.logsed -n "/24\/01\/2013 09:10/,/24\/01\/2013 10:45/p" server.log24/01/2013 09:10 sssssssssssssss cccccccccccccc nnnnnnnnnnnnn 24/01/2013 10:10 uuuuuuuuuuuuuuu jjjjjjjjjjjjjj llllllllllllll mmmmmmmmmmmmm 24/01/2013 10:30... (22 Replies)
Discussion started by: amazigh42
22 Replies

5. Shell Programming and Scripting

Check file created is less than 4 hours or not.

Hi, I need to check some files in one directory whether any files has been created before 4 hours(ie, less than 4 hours from the current time). Can anybody help me out..? Thanks in advance..! (21 Replies)
Discussion started by: Kattoor
21 Replies

6. Shell Programming and Scripting

Take action only if a file is X hours (or seconds) old

shell: #!/bin/ash I searched and found a few relevant posts (here and here - both by porter, on the same day (?)) however both are just a do while loop, I need to check a file date and compare it to the current time. I would like it to say if file 'test' is more than 12 hours old than "right... (3 Replies)
Discussion started by: phdeez
3 Replies

7. Shell Programming and Scripting

finding the file which is modified within last 2 hours

hi, I want to find a file which is modified within last 2 hours i am using sun-os i tried find . -name <filename> -mmin 120 i found that mmin option is not supported in sun-os is there any other alternative option suggestions welcome thanks in advance (5 Replies)
Discussion started by: trichyselva
5 Replies

8. Shell Programming and Scripting

how to list files between last 6 hours to 3 hours

Hi Frens, I want to list some files from a directory, which contains "DONE" in their name, i am receiving files every minute. In this i want to list all the files which are newer than 6 hours but older than 3 hours, of current time i dont want my list to contain the latest files which are ... (4 Replies)
Discussion started by: Prat007
4 Replies

9. UNIX for Dummies Questions & Answers

Finding a file created within the last 24 hours

which out of atime, ctime, or mtime are the closest to diplaying only the files created within the last 24 hours. is it even possible to find only the files created in the last 24 hours, because I heard that unix files don't hold the creation time as a property of the file. (3 Replies)
Discussion started by: raidkridley
3 Replies

10. Shell Programming and Scripting

move log files over 12 hours old...

Hi, I know I can use touch and find's "! -newer" option to list files that are older than a specific time, but what is a good way to get a list of files that are over 12 hours old? The log pruner will run throughout the day, twice an hour. So I can't easily use a cronjob touch command to generate... (1 Reply)
Discussion started by: Thomas Pluck
1 Replies
Login or Register to Ask a Question