The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Compare date from db2 table to yesterday's Unix system date sasaliasim Shell Programming and Scripting 9 12-01-2008 11:37 PM
Date parsing into string, help! martyb555 Shell Programming and Scripting 5 02-17-2008 10:12 PM
need to create a file with its name having system date hamsa Shell Programming and Scripting 11 10-18-2006 04:48 AM
Command DATE in UNIX System ZINGARO UNIX for Dummies Questions & Answers 3 07-20-2006 05:07 PM
file date vs. system date ober5861 UNIX for Dummies Questions & Answers 8 09-11-2001 02:36 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-09-2007
cjones cjones is offline
Registered User
  
 

Join Date: Jan 2007
Posts: 3
parsing a system log file via the 'date' command

Hello,

I'm trying to update some scripts here that parse our system logs daily. They report information just fine... but they just report too much info.

Specifically, if there's been some failed login attempts on several different days (say Monday and Tuesday), when I get the report from Wendsday, I don't want to see Wednesday's info *in addition* to Monday & Tuesday (and so on throughout the week).

This is happening because of this syntax that I've found isn't working:

grep -i fail $LOGDIR/$LOG2 |grep `date |awk '{print $2}' ` | grep `date |awk '{print $3}'

This is giving me information for every day in my logfile... not just on the day the script is running - which is what I prefer.

It seems like if I could make use of this aspect of the date command I'd be ok:

% date '+%C'
Wed May 9 08:23:20 EDT 2007

since the 'May 9' (May, with two spaces and then the 9) is exactly how the syntax of the month/day shows up:

May 9 08:27:10 mysystem sshd2[15562]: [ID 702911 auth.error] auths-pam: PAM subprocess returned packet SSH_PAM_OP_ERROR. (err_num: 9, err_msg: Authentication failed)
May 9 08:27:10 mysystem sshd2[15562]: [ID 702911 auth.notice] Password authentication for user cjones failed (from xxx.xxx.xxx.xxx port 53341).

So... my thinking is that if I could find the right use of the 'date' command then I could use that with a grep to pull out *exactly* what I want out of my logfiles. But it's also possible there's a different way to get the same results.

I'd prefer to do this in a sh/csh script also.

Thanks in advance!

-chris
  #2 (permalink)  
Old 05-09-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
Code:
day=`date +%d`
dt=`date +%b`" "${day#0}
grep "$dt.*fail" filename
  #3 (permalink)  
Old 05-09-2007
cjones cjones is offline
Registered User
  
 

Join Date: Jan 2007
Posts: 3
Quote:
Originally Posted by anbu23
Code:
day=`date +%d`
dt=`date +%b`" "${day#0}
grep "$dt.*fail" filename
Thanks for the help... but when I cut/paste just those lines into a bourne shell script I get a 'bad substitution' error message. Here's my simple little script:

#!/bin/sh

day=`date +%d`
dt=`date +%b`" "${day#0}
grep "$dt.*fail" /var/adm/SYSLOG

I figure I'm missing something simple.

-chris
  #4 (permalink)  
Old 05-09-2007
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,355
Seems that your shell doesn't support pattern syntax ${day#0}
Try:
Code:
day=`date +%d`
dt=`date +%b`" "`echo ${day}|sed 's/^0//'`
grep "$dt.*fail" /var/adm/SYSLOG

Jean-Pierre.
  #5 (permalink)  
Old 05-10-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
Quote:
Originally Posted by cjones
Thanks for the help... but when I cut/paste just those lines into a bourne shell script I get a 'bad substitution' error message. Here's my simple little script:

#!/bin/sh

day=`date +%d`
dt=`date +%b`" "${day#0}
grep "$dt.*fail" /var/adm/SYSLOG

I figure I'm missing something simple.

-chris
Code:
day=`date +%d`
dt=`date +%b`" "`expr $day + 0`
grep "$dt.*fail" filename
  #6 (permalink)  
Old 05-10-2007
cjones cjones is offline
Registered User
  
 

Join Date: Jan 2007
Posts: 3
Thanks to all ... I was able to get what I needed with all of your help.

-chris
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 09:27 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0