LinuxQuestions.org
Register a domain and help support LQ
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, 04: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, 05: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, 05: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, 05:12 PM   #4
Habitual
LQ Addict
 
Registered: Jan 2011
Location: Youngstown, Ohio
Distribution: LM17.1/Xfce4.11.8
Posts: 7,159
Blog Entries: 10

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

Last edited by Habitual; 04-26-2013 at 05:16 PM.
 
Old 04-26-2013, 05: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, 05:17 PM   #6
Habitual
LQ Addict
 
Registered: Jan 2011
Location: Youngstown, Ohio
Distribution: LM17.1/Xfce4.11.8
Posts: 7,159
Blog Entries: 10

Rep: Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968
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, 05: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, 10:43 AM   #8
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
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, 10:45 AM   #9
Habitual
LQ Addict
 
Registered: Jan 2011
Location: Youngstown, Ohio
Distribution: LM17.1/Xfce4.11.8
Posts: 7,159
Blog Entries: 10

Rep: Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 05:52 PM
How to list command history from yesterday? thomas2004ch Linux - Software 2 02-01-2011 08:07 AM
CAT Command ouncya Linux - Newbie 11 08-26-2007 12:48 AM
cat command juanb Linux - Newbie 4 08-19-2004 12:14 PM
cat Command Moeses Linux - General 1 06-20-2002 04:27 AM


All times are GMT -5. The time now is 10:33 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration