The UNIX and Linux Forums  


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



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

Reply
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-30-2009
gogol_bordello's Avatar
Registered User
 

Join Date: Jul 2008
Location: Spain
Posts: 27
Problems getting files date on script

Hello guys,
this script partially works but it's still pretty ugly and, moreover, if the month is jan/feb/mar... it doesn't work at all.

Could anyone say me how to correct, cut and clean a little bit?


Code:
#!/usr/bin/ksh
[...]
egrep -v -e "^\s*#" /file/permission | awk '{ print $1 }' | sort | uniq | while read USER

do
LASTMONTH=`date "+%m"
let FIRSTMONTH=$LASTMONTH-3
let i=$FIRSTMONTH

 while [ $i -eq $LASTMONTH ]
  do
   n=`printf "%02d\n" $i`
   egrep $USER /var/log/access.2009$n >/dev/null || echo $USER >> $FILE
   let i=$i+1
  done
done

Best Regards

Last edited by gogol_bordello; 11-30-2009 at 10:55 AM..
  #2 (permalink)  
Old 11-30-2009
DukeNuke2's Avatar
Soulman
 

Join Date: Jul 2006
Location: Germany, Berlin
Posts: 3,216
first thing i see is a missing ` at the end of the LASTMONTH line. next is the $LASTMONTH-3 should not work... should be something like "FIRSTMONTH=$(expr $LASTMONTH - 3)".
this isn't tested and so only a guess...
  #3 (permalink)  
Old 11-30-2009
Moderator
 

Join Date: Feb 2007
Location: The Netherlands
Posts: 4,670
Not sure what you're trying to achieve, maybe you can do the whole stuff with one awk command.
  #4 (permalink)  
Old 11-30-2009
gogol_bordello's Avatar
Registered User
 

Join Date: Jul 2008
Location: Spain
Posts: 27
for ` it was just a digit error.

I'm trying to verify if I could find a specific string ($USER) on last three months logs.
My logs files are like:

Code:
/var/log/access.200901
/var/log/access.200902
/var/log/access.200903
/var/log/access.200904

etc...


I've year problem too... I means, what will happen with my scripts on jan 2010? :-/
tnks
Sponsored Links
Reply

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 Off


More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Script to clean nmon logs on AIX outtacontrol Shell Programming and Scripting 4 09-04-2008 02:00 AM
Help me clean this up scanner248 UNIX for Dummies Questions & Answers 1 10-15-2007 05:31 PM
Startup script to clean out trash can Andrek OS X (Apple) 4 10-19-2006 04:34 PM
clean up script mpang_ Shell Programming and Scripting 1 07-18-2006 12:14 AM
writing script to clean up a directory ajaya Shell Programming and Scripting 0 04-26-2006 11:18 AM



All times are GMT -4. The time now is 12:02 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
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