need a code for moving the log files older than 2 months

Hi Viewer,

I need logic code for moving the logs files from one directory to another directory.

source :/xxxxxx/ xxxxxx / xxxxxx / xxxxxx / log --- under log directory we have so many files from last two years

Here I need to check the files older than two months and I need to move in to below destination path

Destination: / xxxxxx / xxxxxx /2011

So please help me out to make this script

Thanks,
Asker
:wall:

Try:

cd /source/path/log; find . -type f -mtime +60 -exec mv {} /destination/path/2011 \;

Thanks am i mplementing the same here i need to find out one more thing while moving i need to zip it and moved to destination path

And finally i need this as a cron job daily which has to run at 00:00

Advance thanks for your help.

---------- Post updated at 07:06 AM ---------- Previous update was at 06:51 AM ----------

The requires thing is older than two months files only i need to move not the latest ones

Hi,

This kind of work is the job of logrotate.

Take a look at man logrotate

I'm pretty sure you will find all the answer there.

Thanks I checked however no luck am not able to make the script please provde the script

Hi,

Sorry but i will not provide a script when you have not provided any try you made, the goal is not to work for you, but to help you find a solution.

So i'll just point some option of logrotate that may help you find a solution.

man logrotate
.....

       compress
              Old  versions  of  log  files  are  compressed  with  gzip(1) by
              default. See also nocompress.
....
       olddir directory
              Logs are moved into directory for rotation. The  directory  must
              be  on  the  same physical device as the log file being rotated,
              and is assumed to be relative to the directory holding  the  log
              file unless an absolute path name is specified. When this option
              is used all old versions of the log end up in  directory.   This
              option may be overridden by the noolddir option.
....
       firstaction/endscript
              The lines between firstaction and endscript (both of which  must
              appear  on lines by themselves) are executed once before all log
              files that match the wildcarded pattern are rotated, before pre�
              rotate  script is run and only if at least one log will actually
              be rotated. These directives may only appear inside a  log  file
              definition.  If the script exits with error, no further process�
              ing is done. See also lastaction.
....
       monthly
              Log files are rotated the first time logrotate is run in a month
              (this is normally on the first day of the month).
.....

If the destination directory is not on the same device as the source directory of the logs i'm sure you can find a way to do that with the postrotate/endscript option.

Good luck.