I want my log rotate to delete the log file which are older than 7 days - logrotate

I want logrotate to delete the log file which is older than 7 days. I have tried with maxage 7 but by not mentioning the rotate(count) keeps only one log after rotation, Again I have learned that logrotate will only do other stuff if it is able to rotate at least one file.
I have tried with something like this:
directory path/log.json {
size 1M
compress
maxage 5
missingok
}
Any help for the same wouold be appriciated.

Related

Logrotate : Is there a way to append log contents when rotation happens multiple times a day

I'm trying to rotate logs daily EXCEPT when my logfile is over 500M then it should be rotated asap, so I've copied my /etc/cron.daily/logrotate into /etc/cron.hourly and my config file looks like this :
compress
missingok
/path/to/my/logfile.log
{
daily
maxsize 500M
ifempty
copytruncate
olddir /path/to/my/archived/logs/
dateext
}
the dateext is here to make sure the log rotation works the same way as the old log rotation tool (several dedicated custom scripts).
As it is, when logfile.log is over 500M a rotation happens, which create logfile.log.YYYYMMDD.gz, but if logfile.log reaches again 500M the same day (which is more than likely to happen) then I have an issue since logfile.log.YYYYMMDD.gz already exists.
So my quesion is, Is there a way to append the log content into an already existing rotated log file, in order to have only one archived log per day ?

How to correct/time shift subtitles in multiple SRT files?

Is there a way to badge edit multiple .srt files. We have a project where recent edits to videos offset the .srt files by 5 seconds. I know how to timeshifts .srt on a single file, but I'm wondering if there is a way to timeshift 1000s of .srt files by 5 seconds.
Most command lines I'm aware off can do it file by file, but I haven't seen it work on folders.
This is an interesting challenge. You'd almost certainly have to write some short script to do this. Command line tools like sed and awk are great for text processing tasks like this, but the challenge I think you'll face is the timecode. It's not as simple as just adding 5 to the seconds field of each timecode because you might tip over the edge of a minute (i.e. 00:00:59.000 + 5 = 00:01:04.000). You'll have to write some custom code to handle this part of the problem as far as I know.
The rest is pretty straight forward, you just need a command like find . -name ".srt" | xargs the-custom-script-you-have-to-write.sh
Sorry it's not a more satisfying answer. I don't know of any existing utilities that do this.

logrotate deletes 2nd day old file, which should not happen

i need to rotate log files and i am able to do that, but once files are rotated after two day old file is being deleted, i don't want that to happen, below is my config
/home/logs/catalina.out {
su root root
copytruncate
notifempty
daily
dateext
dateformat -%Y-%m-%d
rotate 4
compress
missingok
}

What is "rotate 13" in "/etc/logrotate.conf" file?

What is meant by "rotate 13" in "/etc/logrotate.conf" file? Can this be changed to "rotate 4" ?
$ cat /etc/logrotate.conf
# see "man logrotate" for details
# rotate log files weekly
weekly
# keep 4 weeks worth of backlogs
rotate 13
The comment is not correct.
This statement keeps 13 weeks worth of the logs.
'rotate' means that it keeps the old logfiles for as many cicles as specified. (A cycle is in your case a week)
From the documentation at https://linux.die.net/man/8/logrotate
rotate count
Log files are rotated count times before being removed or mailed to the address specified in a mail directive. If count is 0, old versions are removed rather than rotated.
The rotate command determines how many archived logs are returned before logrotate starts deleting the older ones.
You can read more about it here and here.
rotate 13 means logrotate rotate the log files till count 13, after that logrotate start to shift the files: like logfile_1 shifted to logfile_2 and logfile_2 shifted to logfile_3 and so on. for that logrotate discard the last logfile_13 and create a new file at logfile1

Logrotate doesn't work automatically (using size limit)

It seems that my rotation is not working. If I execute the logrotate manually it's working like it should. The logrotate is ran because I can see it in the logs. Here's what I have:
# see "man logrotate" for details
# rotate log files weekly
weekly
# keep 4 weeks worth of backlogs
rotate 4
# create new (empty) log files after rotating old ones
create
# use date as a suffix of the rotated file
dateext
# uncomment this if you want your log files compressed
#compress
# RPM packages drop log rotation information into this directory
include /etc/logrotate.d
/home/www/logs/access_log {
sharedscripts
delaycompress
size 2G
compress
dateext
maxage 30
postrotate
/usr/local/bin/apachectl -k graceful
endscript
}
Any clue?
It's an old question, but someone might find this helpful.
The default rotation settings indicate weekly rotation, but your configuration for access log below specifies rotation by size.
These settings will not work at the same time. It's either time or size.
For access logs, I would advise daily rotation.
If your logs grow over 2GB during the day, then you will need to run logrotate hourly. This ensures that logrotate will check the size of your log and rotate accordingly.
This however, implies that you have to add time stamp to your logs, because you would want to have multiple logs for the same day, right?
There is also maxsize parameter for logrotate, and it's supposed to work together with time based rotation (daily, weekly etc) but I'm not sure if it works. You will need to experiment.