问题原文
原帖链接 · Moritz · CC BY-SA 4.0
I am new to Linux/CentOS and right now I am running into a little problem.
My CentOS7 Server logs all Maillogs, via Logrotate, on a daily basis and moves them to the folder /var/log/old_maillogs. Right now the logs are saved with a name similar to this:
Maillog-20230721
I would like their names to change, based on how old they are, so that if the Log is one day old it's named:
Maillog-1
And one the day after that, the files name changes to:
Maillog-2
And so on.
Is this even possible, if so, what would be the smartest way to get it working? I have read a lot about scripts that get executed once per day, but then again, how do I code the script, so that it recognizes how many logs are in the folder?
This is my current config:
/var/log/maillog{
daily
rotate 365
postrotate
Systemctl restart rsyslog.service
endscript
mailfirst
olddi /var/log/old_maillog
}
已采纳解答
原帖链接 · asktyagi · CC BY-SA 4.0
Please refer logrotate man page option "start count"
start count
This is the number to use as the base for rotation. For example, if you specify 0, the logs will be created with a .0 extension as they are rotated from the original log files. If you specify 9, log files will be created with a .9, skipping 0-8. Files will still be rotated the number of times specified with the count directive.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
