LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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 08-12-2014, 06:40 AM   #1
skoda
Member
 
Registered: Jun 2013
Posts: 111

Rep: Reputation: Disabled
Strange Bash Script Date related issue


Hai folks,

The log file

Quote:
/var/log/messages:Aug 10 04:16:47 host pure-ftpd: (?@xxx.xxx.xxx.xx) [INFO] bangl is now logged in
/var/log/messages:Aug 11 04:17:16 host pure-ftpd: (?@xxx.xxx.xxx.xx) [INFO] changn is now logged in
/var/log/messages:Aug 12 04:18:08 host pure-ftpd: (?@xxx.xxx.xxx.xx) [INFO] eurowest is now logged in
now i want to extract logs dynamically by date

Quote:
dt=$(date +"%b %d")
echo $dt
egrep 'ftpd.*is now logged in' /var/log/messages* | grep -v '__cpanel' | grep $dt > ftp.txt
out put shows Aug 12 (today's date)
but the ftp.txt is empty.

now if i changed the above as follows (see the red color text) it correctly extract the Aug 12 log. what could be wrong?

Quote:
dt=$(date +"%b %d")
echo $dt
egrep 'ftpd.*is now logged in' /var/log/messages* | grep -v '__cpanel' | grep "Aug 12" > ftp.txt
out put (the content of ftp.txt) :

/var/log/messages:Aug 12 04:18:08 host pure-ftpd: (?@xxx.xxx.xxx.xx) [INFO] eurowest is now logged in

Last edited by skoda; 08-12-2014 at 06:42 AM.
 
Old 08-12-2014, 06:51 AM   #2
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 2,166

Rep: Reputation: 751Reputation: 751Reputation: 751Reputation: 751Reputation: 751Reputation: 751Reputation: 751
Use this:

Code:
egrep 'ftpd.*is now logged in' /var/log/messages* | grep -v '__cpanel' | grep "$dt" > ftp.txt
Without the quotes around $dt it gets treated as two parameters, Aug and 12.
 
Old 08-12-2014, 07:01 AM   #3
skoda
Member
 
Registered: Jun 2013
Posts: 111

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by TenTenths View Post
Use this:

Code:
egrep 'ftpd.*is now logged in' /var/log/messages* | grep -v '__cpanel' | grep "$dt" > ftp.txt
Without the quotes around $dt it gets treated as two parameters, Aug and 12.
awesome sir!!
yes got the point
 
Old 08-12-2014, 07:05 AM   #4
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 2,166

Rep: Reputation: 751Reputation: 751Reputation: 751Reputation: 751Reputation: 751Reputation: 751Reputation: 751
You're welcome.
 
Old 08-12-2014, 08:30 AM   #5
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 5,387

Rep: Reputation: 397Reputation: 397Reputation: 397Reputation: 397
greping the "date + pure-ftpd" before other filters might be more efficient
 
  


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
[SOLVED] Strange issue with Bash script and resolution Jinx-Wolf Programming 7 03-19-2011 07:03 PM
issue related to shell script manglesh.vyas Linux - Newbie 2 12-07-2010 06:39 PM
Strange if statement behaviour when using bash/bash script freeindy Programming 7 08-04-2008 07:00 AM
Date calculations in BASH script Crashman Programming 4 07-03-2004 11:15 AM
Date in a BASH script... soulsniper Linux - Software 7 11-22-2003 07:08 PM


All times are GMT -5. The time now is 01:00 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