LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices

Reply
 
Search this Thread
Old 07-02-2012, 03:49 AM   #1
andycol500
LQ Newbie
 
Registered: Mar 2012
Posts: 15

Rep: Reputation: Disabled
Script to pull all lines with todays date


Hi Guys

Any ideas how I can script it to find todays date and then pull all lines out of /var/log/secure with todays date then > into a file.

cat /var/log/secure | grep "date +"%b %d""
Doesnt seem to work
Any ideas
 
Old 07-02-2012, 04:15 AM   #2
whizje
Member
 
Registered: Sep 2008
Location: The Netherlands
Distribution: Slackware64 current
Posts: 582

Rep: Reputation: 129Reputation: 129
Could you post how the date is specified in the log file.
 
Old 07-02-2012, 04:27 AM   #3
rosehosting.com
Member
 
Registered: Jun 2012
Posts: 222

Rep: Reputation: 62
Quote:
Originally Posted by andycol500 View Post
Hi Guys

Any ideas how I can script it to find todays date and then pull all lines out of /var/log/secure with todays date then > into a file.

cat /var/log/secure | grep "date +"%b %d""
Doesnt seem to work
Any ideas

A quick and dirty hack would be something like this:

Code:
MONTH=$(date +%b)
DAY=$(date +%d)
DAY=${DAY#0}

grep "${MONTH}  ${DAY}" /var/log/secure
since the log file format is like the following:

Code:
Jul  1 10:26:14
Jul  2 10:26:13
hope that helps

EDIT: as a side note, you have a useless use of `cat` there. `grep` is able to handle a file as an argument so you do not need to `cat`-it and then grep through the lines returned by `cat`.

Last edited by rosehosting.com; 07-02-2012 at 04:30 AM.
 
Old 07-02-2012, 05:06 AM   #4
andycol500
LQ Newbie
 
Registered: Mar 2012
Posts: 15

Original Poster
Rep: Reputation: Disabled
Thanks and if I want to make it for one day ago
what would I change?
 
Old 07-02-2012, 05:08 AM   #5
rosehosting.com
Member
 
Registered: Jun 2012
Posts: 222

Rep: Reputation: 62
Quote:
Originally Posted by andycol500 View Post
Thanks and if I want to make it for one day ago
what would I change?
Code:
DAY=$(date +%d --date="yesterday")
that will give you the date of yesterday.

 
  


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
script to omit lines based on date jasem200 Linux - Server 2 09-21-2009 07:03 AM
Delete files in folder before todays date dave7802 Linux - Newbie 1 09-14-2009 05:03 AM
script help - pull date format out of file name and compare to today MaureenT Linux - General 5 11-06-2008 11:14 AM
Uploading all files with todays date via kermit isourcemarketing Programming 2 08-26-2007 08:27 PM
Bash script to read file and alter lines depending on create date ChristianHein Linux - General 13 08-04-2007 05:39 AM


All times are GMT -5. The time now is 11:46 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration