Log file rotation

Hi

I am trying to create a simple function that implements log rotation

rotatelogs ()  {
file_name=$1
archive_dir=$2
retention_period=$3

find $archive_dir -name $file_name -mtime +$retention_period -exec rm -f {} \;

}

Issue i am facing is the file_name would be something like my sybase-log.

The archive dir would have many files like

sybase-log-14-Feb-2010
sybase-log-15-Feb-2010
..
sybase-log-28-Feb-2010
sybase-log-01-Mar-2010

My log rotation script should delete only these two files
sybase-log-14-Feb-2010
sybase-log-15-Feb-2010

Can anybody let me know how do write this find command ?

find $archive_dir -name $file_name -mtime +$retention_period -exec rm -f {} \;

regards

What system are you working on?

On Linux, there is already a very good program for this, and it is called:

logrotate

You use logrotate command as neo said.Otherwise tell me,what are the arguments you passed to your function.

Hi

My script needs to work on many flavours of unix.

file_name=$1 Name of the file
archive_dir=$2 Archive directory
retention_period=$3 retention period in days

regards