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

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting need a code for moving the log files older than 2 months
# 1  
Old 05-21-2011
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

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

# 3  
Old 05-21-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
# 4  
Old 05-21-2011

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.
# 5  
Old 05-21-2011
Thanks I checked however no luck am not able to make the script please provde the script
# 6  
Old 05-21-2011

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

              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.
              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.
              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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

To nullify multiple log files older than X days.

Hi, I am writing the script for tomcat logs clean up ending with *.txt and *.log. cleanup should be applied to logs older than 7 days logs same will be scheduled in cron. after googling found below but it only help partially. find . -type f -name '*.log' -exec truncate --size 0 "{}" \; I... (6 Replies)
Discussion started by: Riverstone
6 Replies

2. Shell Programming and Scripting

Deleting files and directory's older than 3 months

I have a qnap TS259 that is running ubuntu. Have successfully setup back scripts that are initiated by cron. I would like to create a couple scrypts that would operate on the recycle bins for both drives. Just want to be able to run the script manually that would walk through both directories... (13 Replies)
Discussion started by: mackconsult
13 Replies

3. Red Hat

Need Script to ZIP/SAVE & then DELETE Log file & DELETE ZIPS older than 12 months

ENVIROMENT Linux: Fedora Core release 1 (Yarrow) iPlanet: iPlanet-WebServer-Enterprise/6.0SP1 Log Path: /usr/iplanet/servers/https-company/logs I have iPlanet log rotation enabled rotating files on a daily basis. The rotated logs are NOT compressed & are taking up too much space. I... (7 Replies)
Discussion started by: zachs
7 Replies

4. UNIX and Linux Applications

Firefox 10 keeps losing history older than 2 months

Can anyone explain why Firefox 10 keeps losing history older than 2 months? (1 Reply)
Discussion started by: cokedude
1 Replies

5. Shell Programming and Scripting

Command to Count the files which is Older than 3 months?

Hi Gurus the count of files in a particular Directory... ls -lrth | grep -c ^- can any one share the command to Count the files which is Older than 3 months So please help me out in this Thanks in Advance (2 Replies)
Discussion started by: SeenuGuddu
2 Replies

6. Shell Programming and Scripting

gzip files older than 1 months

Hello, I want to gzip files in a folder in bulk i.e. all files older than 1 month should be in *.gz format. Could you please suggest how this can be achieved. Thanks. Regards, Alok (1 Reply)
Discussion started by: alok1301
1 Replies

7. Shell Programming and Scripting

Finding files older than the current date and time and renaming and moving

Hi, I have a very urgent requirement here. I have to find all files in the specified directory but not in the sub directories(The directory name is stored in a variable) which are older than the current date as well as current time and rename it as filename_yyyymmddhhmmss.ext and move it into a... (7 Replies)
Discussion started by: ragavhere
7 Replies

8. Shell Programming and Scripting

Delete files older than 3 months.(read date from the name of the file)

Guys, My log files stored in the date format format below(log_20080714072942): TIMESTAMP=`date +%Y%m%d%H%M%S` LOG=/log/log_${TIMESTAMP}.log I'm looking for a shell script which deletes all files which is older than 3 months from today. Regards, Bhagat (3 Replies)
Discussion started by: bhagat.singh-j
3 Replies

9. Solaris

Find 3 months old log files and remove

HI I HAVE LOG FILES IN THIS FORMAT XXX.log.20080509215745 XXX.log.20080209205745 XXX.log.20080301785745 XXX.log.20080109155745 XXX.log.20080409115745 XXX.log.20080309105745 I NEED TO FIND THE FILES FROM 3 MONTHS OLD AND REMOVE PLEASE HELP THANKS, (13 Replies)
Discussion started by: cvdev
13 Replies

10. Shell Programming and Scripting

Listing files older than 2 months

A script or command to list files older than 2 months in a specified directory and remove it. (3 Replies)
Discussion started by: pbekal
3 Replies
Login or Register to Ask a Question

Featured Tech Videos