Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Let's say I have the following files in /my/path/to/logfiles:
-rw-r--r-- 1 user user 11K May 16 12:37 file1.log
-rw-r--r-- 1 user user 250 May 17 09:54 file2.log
-rw-r--r-- 1 user user 22K May 14 10:41 file3.log
-rw-r--r-- 1 user user 1.3K Jun 19 13:43 file4.log
-rw-r--r-- 1 user user 1.7K Jun 29 11:14 file5.log
-rw-r--r-- 1 user user 36K Jun 25 12:35 file6.log
-rw-r--r-- 1 user user 37K Jun 29 14:18 file7.log
and with the original config, I expect files file1,2 and 3 to be deleted.
From the man page, for rotate, I understand that it will keep given number of copies of a file. For example, in the above list, if file1 is more than 10 days older, it will be copied to file1.log.1(for example) and after another 10 days it will be moved to file1.log.2 upto file1.log.10 and then deleted after that.I don't think it is something like what you have said (that's what the maxage is for). rotate will simply keep the given number of copies either compressed or not depending upon the compress/nocompress parameter. A rotate 0 will just delete the file when a condition is met (like daily, monthly, maxage, size etc).
Additionally the -f option is to force the logrotation even if logrotate thinks that a file is not ready for a rotation (f is not for file but force).
maxage will delete rotated logs only, not the original files. And with rotate 0 you avoid creating log files.
So, the question is: what has to be older than ten days? The original files, or the rotated ones (being compressed or not). Do you get so many files just in ten days?
I think that's what I have misunderstood. You are right. maxage removes the rotated files of count days. I have misunderstood it to the maxage of the actual files.
To answer your question, I want the actual file to be removed (without rotating) if it is older than 10 days. I think I have given a use case in #5.
10 days is just an example case. Practically it will be between 30 to 90 days on different situations.
Please let me know if you need more information in this regard.
To answer your question, I want the actual file to be removed (without rotating) if it is older than 10 days. I think I have given a use case in #5.
But stuff is added to the logfiles by the syslog several times a day. Do you want the files to be removed if nothing was added for ten days, and so modification date wasn’t updated? And if you do so, all old information therein would be gone.
Yeah, that's fine. I do not care whatever that is in the file. I do not want them anyhow after the x number of days.
PS: To be honest those are the log files created by a set of automated scripts developed by me. They provide some forensic information about any failures and will not be needed after few days.
This is no task for logrotate then IMO. A plain cron job where you look for the modification date and delete the files would do already. Create a file in /etc/cron.daily:
Reuti has got a point there. In fact, that is how I have implemented it currently.
The reason I wanted to move towards logrotate is because it is a standard way of 'handling' the log files. Whether it is the right way or not should the logrotate not be working for this task?
Anyhow, I am not going to spend much time on this. I going to stay with the current setup.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.