1837900 Members
3130 Online
110123 Solutions
New Discussion

Re: delete record

 
haeman
Frequent Advisor

delete record

I have a log file , that keep the record of system activities , as below , now the log is appending so that it becomes very large .

"
05/01/08 Normal userA
05/01/08 Normal userB
05/02/08 Alnormal userC
"
"
10/01/08 Normal userA
10/02/08 Normal userA
"


Now I would like to keep the log current , so if the date is over 60 days , then remove this row , like above , the first three row should be removed as 05/01/08 and 05/02/08 is over 60 days ( today is 10/08/08 ) , can advise how to do it ? thx
6 REPLIES 6
Yogeeraj_1
Honored Contributor

Re: delete record

hi,

did you look into LOGROTATE?

Quote from Man logrotate:

logrotate is designed to ease administration of systems that generate large numbers of log files. It allows automatic rotation, compression, removal, and mailing of log files. Each log file may be handled daily, weekly, monthly, or when it grows too large.


if your requirements are not that strict, you may wish to implement this.

hope this helps!
kind regards
yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Dennis Handly
Acclaimed Contributor

Re: delete record

You either need a perl script that does date arithmetic, or you need to do the work yourself.

See caljd script in:
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1173649
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=213185

After you get the date for 2 months ago, you could use sed to remove up to that date:
sed "1,\\:$OLD_DATE: d" log
haeman
Frequent Advisor

Re: delete record

thx replies,

LOGROTATE could do the requirement , it could check the date ( eg. 05/02/08 ) in the log ? thx
Yogeeraj_1
Honored Contributor

Re: delete record

hi,

Please read the docs.

e.g.
Please see:
http://www.debian-administration.org/articles/117


With logrotate, you will have to define the rules as per the specifications. I think it is better to implement something more generic.

otherwise you can implement the solution provided by Dennis above.

kind regards
yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
haeman
Frequent Advisor

Re: delete record

thx reply ,

I tried the script in the link
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=213185

but I have some problem when run it in my distro .

I have read the man page of logrotate , I think the below part is function works for my case , but I am not too understand how it fit to my requirement , could advise do I need to write the script to make it ? thx

/var/log/news/news.crit {
monthly
rotate 2
olddir /var/log/news/old
missingok
postrotate
kill -HUP ?ç at /var/run/inn.pid??
endscript
nocompress
}

haeman
Frequent Advisor

Re: delete record

thx reply ,

can advise what can i do ?