OK, here is the output from a cron I have here:
FULL OUTPUT:
acoxxx Lastlogin= 2010/07/15 13:10
db2t Lastlogin= 2010/07/16 13:09
db2tadm Lastlogin= 2010/07/20 13:09
eisuser Lastlogin= 2010/07/20 11:53
israel Lastlogin= 2010/07/10 11:42
nmon Lastlogin= 2010/07/05 12:55
norbac Lastlogin= 2010/07/04 14:21
oracle Lastlogin= 2010/07/03 08:05
root Lastlogin= 2010/07/03 13:01
s03josa0 Lastlogin= 2010/07/01 14:10
I'm looking for a script that 'grep' ONLY the lines older than N days.
Example: "Lastlogin older than 10 days":
OUPUT:
nmon Lastlogin= 2010/07/05 12:55
norbac Lastlogin= 2010/07/04 14:21
oracle Lastlogin= 2010/07/03 08:05
root Lastlogin= 2010/07/03 13:01
s03josa0 Lastlogin= 2010/07/01 14:10
How can I do this?
thanks
ISrael.
lets just say your cron output is stored in a file named file1
then you can use something like this:-
awk -v f=0 '/2010/07/10/ {f=0} { print > "file_"f }' file1
this will place all the lines before the date 2010/07/10 into file0. but in this case you have to enter the date manually. i mean the date 10days earlier date. or you can take it as a parameter. or pass it via giving output of find command.
Hi daz,
it gives me an error:
israel@bsades2: /home/israel # awk -v f=0 '/2010/07/10/ {f=0} { print > "file_"f }' /tmp/prueba1
Syntax Error The source line is 1.
The error context is
/2010/07/10/ >>> { <<<
awk: 0602-500 Quitting The source line is 1.
What's wrong? Thanks
---------- Post updated at 09:44 AM ---------- Previous update was at 09:17 AM ----------
daz,
What if I the date is 36 days?
thanks
Israel.
With GNU date, or you give the date directly to $DATE by format as 20100710
DATE=$(date -d "36 days ago" +%Y%m%d)
awk -v d="$DATE" '{t=$3;gsub(/\//,"",t)}{if (t<d) print} ' urfile
Hi rdcwayx,
I think I don't have gnu-date because I'm on AIX6.1. Thanks.