LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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, 02:29 AM   #1
ust
Senior Member
 
Registered: Mar 2003
Location: fasdf
Distribution: Debian / Suse /RHEL
Posts: 1,130

Rep: Reputation: 31
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, 04:13 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
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 04:16 AM.
 
Old 10-12-2008, 08:35 PM   #3
ust
Senior Member
 
Registered: Mar 2003
Location: fasdf
Distribution: Debian / Suse /RHEL
Posts: 1,130

Original Poster
Rep: Reputation: 31
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, 08:47 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
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 09:11 PM.
 
Old 10-15-2008, 12:36 AM   #5
ust
Senior Member
 
Registered: Mar 2003
Location: fasdf
Distribution: Debian / Suse /RHEL
Posts: 1,130

Original Poster
Rep: Reputation: 31
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, 07:38 PM   #6
ust
Senior Member
 
Registered: Mar 2003
Location: fasdf
Distribution: Debian / Suse /RHEL
Posts: 1,130

Original Poster
Rep: Reputation: 31
can advise what is the simpliest way to do it ? thx
 
Old 10-15-2008, 07:51 PM   #7
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
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



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:14 PM.

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
Open Source Consulting | Domain Registration