LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 07-21-2008, 09:55 PM   #1
noir911
Member
 
Registered: Apr 2004
Posts: 682

Rep: Reputation: Disabled
Logrotate error


I have written a shell script which continuously gets data from a SNMP enabled device to /home/snmp/snmp.log file. All I want logrotate to do is make this file 0 bytes when the file size reaches 1024 bytes (I know 1024 bytes is small but I am at a test phase and once it's all working I will increase that to 10 GB) & back it up to /home/snmp/snmp.log.1

I have created /etc/logrotate.d/snmp file, read the man page and tried various logrotate options but I don't get the desired output. The last option I tried does not truncate the original file to 0 bytes even when I copy /dev/null to the file.

Here is my /etc/logrotate.d/snmp file

Quote:

/home/snmp/snmp.log {
rotate 30
size=1024
nocompress
copytruncate
# copy
postrotate
cp /dev/null /home/snmp/snmp.log
endscript
}
Thanks for any help
 
Old 07-21-2008, 10:36 PM   #2
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 62
I recall this from another of your threads.

You have a race condition, where you are trying to write to a file at the same time another process is writing to the same file. Under this condition, the results are UNDEFINED.

You will not get reliable results in general, and even less with very small file sizes.
 
Old 07-22-2008, 05:15 AM   #3
noir911
Member
 
Registered: Apr 2004
Posts: 682

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Mr. C. View Post
I recall this from another of your threads.
On that post I tried to do this from the shell script. In this post I am trying to use logrotate, which is supposed to rotate logs!

Quote:
Originally Posted by Mr. C. View Post
You have a race condition, where you are trying to write to a file at the same time another process is writing to the same file. Under this condition, the results are UNDEFINED.

You will not get reliable results in general, and even less with very small file sizes.
I am trying to think outside the box. So, there's no way this can be done in a simple manner? No one has ever done this befone?
 
Old 07-22-2008, 11:38 AM   #4
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 62
If you and I both race to get in the drivers seat of your car and we both have keys, which of us will be the driver? Its a race; in this type of race, the first person wins.

In the race condition above, the last person wins, but there is no reliable way to guarantee that you are last, given that you don't control the competing application. If you can control the application, it should perform the close.

Thinking outside the box is excellent. That means to ignore conventional wisdom and brainstorm for imaginative solutions. It does not mean ignore the physical laws of the universe, or clearly defined OS reults which are defined as UNDEFINED. Thinking outside the box will not allow you to do things the OS prevents you from doing, nor will it create order out of chaos

Last edited by Mr. C.; 07-22-2008 at 11:39 AM.
 
  


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
logrotate error - last rotated in the future ocgltd Fedora 1 10-02-2005 08:07 PM
logrotate error @ngelot Linux - Newbie 1 09-02-2005 08:05 PM
logrotate won't run - gives error Avatar Linux - General 2 07-19-2004 10:22 AM
Logrotate Help! MaverickApollo Linux - Software 3 02-19-2004 12:09 PM
Error in Logrotate.status file tomdlam Linux - General 0 10-17-2002 08:38 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 07:33 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