I am trying to write a script which will rename and archive log files but I just can’t figure it out. Here is an example of how it should work: If you have a file named error_log and you run your script for a first time it should rename the file error_log to error_log.1 and then archive error_log.1 with gzip. The second time you run your script you will have two files: error_log and error_log.1.gz, now you should rename error_log.1.gz to error_log.2.gz; error_log to error_log.1 and once again archive error_log.1 to error_log.1.gz with gzip.
I am trying to write a script which will rename and archive log files
Share
What you are looking for is named
logrotate, it’s a basicUnixadministration command to rotate the logs like you’d like.See
man 8 logrotateExample of a simple configuration file :