LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-26-2013, 03:47 PM   #1
mahan77
LQ Newbie
 
Registered: Apr 2013
Location: London
Distribution: centos
Posts: 14

Rep: Reputation: Disabled
cat command for yesterday entries


I like to get yesterday entries from log file so that I can send that to my email every day.
This command will provide today’s from log file

cat /var/log/fail2ban.log | grep `date +%Y\-%m\-%d`

how do i rewrite this command for yesterday entries?
 
Old 04-26-2013, 04:04 PM   #2
cortman
Member
 
Registered: Jan 2012
Location: ZZ9 Plural Z Alpha
Distribution: Crunchbang 11, LFS 7.3, DSL 4.1.10, Lubuntu 12.10, Debian 7
Posts: 219

Rep: Reputation: 43
I found this with Google.
 
Old 04-26-2013, 04:10 PM   #3
mahan77
LQ Newbie
 
Registered: Apr 2013
Location: London
Distribution: centos
Posts: 14

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by cortman View Post
I found this with Google.
This command don't work
 
Old 04-26-2013, 04:12 PM   #4
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Code:
grep $(date +"%Y-%m-%d" --date="1 days ago")  /var/log/fail2ban.log

Last edited by Habitual; 04-26-2013 at 04:16 PM.
 
Old 04-26-2013, 04:14 PM   #5
mahan77
LQ Newbie
 
Registered: Apr 2013
Location: London
Distribution: centos
Posts: 14

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Habitual View Post
Code:
grep $(date +"%Y-%m-%d" --date="1 days ago") /var/log/messages
Thank you so much
 
Old 04-26-2013, 04:17 PM   #6
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Sure!

and it's
Code:
grep $(date +"%Y-%m-%d" --date="1 days ago")  /var/log/fail2ban.log
in case email sent you my first reply.
 
Old 04-26-2013, 04:24 PM   #7
mahan77
LQ Newbie
 
Registered: Apr 2013
Location: London
Distribution: centos
Posts: 14

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Habitual View Post
Sure!

and it's
Code:
grep $(date +"%Y-%m-%d" --date="1 days ago")  /var/log/fail2ban.log
in case email sent you my first reply.
keep up the good work
thanks again
 
Old 04-29-2013, 09:43 AM   #8
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
date +"%F" is the same as date +"%Y-%m-%d", btw.

I'm not familiar with the format of this log, but it appears that the date string we want to match is at the beginning of the line, so I suggest modifying it like this:

Code:
grep "$( date -d '-1 day' +'^%F' )"  /var/log/fail2ban.log
This would keep it from potentially matching any dates elsewhere in the text.
 
1 members found this post helpful.
Old 04-30-2013, 09:45 AM   #9
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
Originally Posted by David the H. View Post
date +"%F" is the same as date +"%Y-%m-%d", btw
and a whole lot less typing, too. Thanks!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
cat command -s , -n doug skillmore Linux - Newbie 2 02-27-2013 04:52 PM
How to list command history from yesterday? thomas2004ch Linux - Software 2 02-01-2011 07:07 AM
CAT Command ouncya Linux - Newbie 11 08-25-2007 11:48 PM
cat command juanb Linux - Newbie 4 08-19-2004 11:14 AM
cat Command Moeses Linux - General 1 06-20-2002 03:27 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:43 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration