My bash script produces a log file. Now i'd like to implement some log file rotation.
Let's say the first time it's called somelog.log, the next time it's renamed to somelog.log.1 and the new log file somelog.log.
The third time the new log is somelog.log again, but somelog.log.1 is renamed to somelog.log.2 and the old somelog.log to somelog.log.1.
I would be able to grant a maximum of eg 5.
Is this done before (sample script), any suggestions. I appreciate any advice.
相关问题
- What is the best way to do a search in a large fil
- JQ: Select when attribute value exists in a bash a
- Spring Integration - Inbound file endpoint. How to
- I want to trace logs using a Macro multi parameter
- Error message 'No handlers could be found for
相关文章
- how do I log requests and responses for debugging
- Check if directory exists on remote machine with s
- What is the correct way to declare and use a FILE
- Making new files automatically executable?
- Reverse four length of letters with sed in unix
- Launch interactive SSH bash session from PHP
- Android Studio doesn't display logs by package
- BASH: Basic if then and variable assignment
I've just made a bash script for that: https://github.com/lingtalfi/logrotator
It basically checks your log file's size, and if it exceeds an arbitrary threshold, it copies the log file into a log directory.
It's cron friendly, or you can use it manually too.
A typical command looks like that:
Try this bash function, it takes two parameters:
source: