LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 10-09-2008, 03:29 AM   #1
ust
Senior Member
 
Registered: Mar 2003
Location: fasdf
Distribution: Debian / Suse /RHEL
Posts: 1,130

Rep: Reputation: 30
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
 
Old 10-09-2008, 05:13 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,241

Rep: Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325
man logrotate

To expand, you can't easily remove the top/front of an open file being written to.
The usual solution is to use the logrotate utility as mentioned.
See /var/log
For a static/non-open file you can extract the top or bottom of a file using the head and tail cmds.

Last edited by chrism01; 10-09-2008 at 05:16 AM.
 
Old 10-12-2008, 09:35 PM   #3
ust
Senior Member
 
Registered: Mar 2003
Location: fasdf
Distribution: Debian / Suse /RHEL
Posts: 1,130

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by chrism01 View Post
man logrotate

To expand, you can't easily remove the top/front of an open file being written to.
The usual solution is to use the logrotate utility as mentioned.
See /var/log
For a static/non-open file you can extract the top or bottom of a file using the head and tail cmds.
except logrotate , can give me the hits to write a script to do that ? thx
 
Old 10-12-2008, 09:47 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,241

Rep: Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325
except logrotate ?? What do you mean?

edit:
if you want
Quote:
For a static/non-open file you can extract the top or bottom of a file using the head and tail cmds.
then to get a copy of the last n lines of a file its

tail -n logfile > newlogfile

1st n lines

head -n logfile > newlogfile

These only take a copy, they don't remove the lines.

If you are prepared to do some programming, many langs eg Perl supply a truncate cmd.

Last edited by chrism01; 10-12-2008 at 10:11 PM.
 
Old 10-15-2008, 01:36 AM   #5
ust
Senior Member
 
Registered: Mar 2003
Location: fasdf
Distribution: Debian / Suse /RHEL
Posts: 1,130

Original Poster
Rep: Reputation: 30
thx reply ,

I tried the script in the link
http://forums.itrc.hp.com/service/fo...hreadId=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
}
 
Old 10-15-2008, 08:38 PM   #6
ust
Senior Member
 
Registered: Mar 2003
Location: fasdf
Distribution: Debian / Suse /RHEL
Posts: 1,130

Original Poster
Rep: Reputation: 30
can advise what is the simpliest way to do it ? thx
 
Old 10-15-2008, 08:51 PM   #7
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,241

Rep: Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325
On my system there's a file

/etc/cron.daily/logrotate

so it gets called daily. The logrotate files (like yours) are stored in

/etc/logrotate.d

you just need to look for the equiv on your distro. You'll need to do it as root.
Looks like you need to fix that kill cmd though... its unreadable here.
 
  


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
DDNS record and a static PTR record mou5e Linux - Networking 2 01-22-2008 02:16 AM
Creating A record and PTR record daemonkl *BSD 3 10-03-2007 05:50 PM
add/delete record in mysql table on linux from a WinXp machine using visual c++ SyncMaster Linux - Enterprise 2 05-30-2005 01:53 AM
Unable to record mic-in with SoundBlaster Live! while able to record other sources max76230 Linux - Newbie 2 03-14-2005 05:31 AM
I need to delete my Main Boot Record(Lilo) RestInPieces Linux - General 5 08-22-2004 05:40 PM


All times are GMT -5. The time now is 07:11 AM.

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