Solved

cron job to move old files to another directory

Posted on 1997-12-09
4
260 Views
Last Modified: 2013-12-25
I am looking for

a.) a code to move old files
   (i.e. older than 21 days) to another dir. (archive)

b:) a script (callable with cron) to delete
    files (i.e. files older than 120 days)

Thanks

Nadia Barelli
0
Comment
Question by:nadia
  • 2
4 Comments
 

Accepted Solution

by:
ke4fom earned 200 total points
Comment Utility
This script should do it if you are running unix.....

For files older than 21 days try this...
find / -ctime 21 -print -exec mv /newdir {} \;

for files older than 120 days.......
find / -ctime +120 -print -exec /usr/bin/rm {} \;

hope that helps
0
 

Expert Comment

by:aurelio
Comment Utility
Also , you can put it in the crontab by the following method , supposing you are using a standard sysV unix :

1) Create a shell script with the find code, e.g.
echo 'find / -ctime 21 -print -exec mv /newdir {} \;'>/home/er.sh

2) list the crontab file , using
crontab -l > /tmp/oldcron

3) insert a new line ; this one launches the script every half hour ; modify according to needs
echo '28,01 * * * * /usr/bin/sh /home/er.sh 1>/dev/null 2>/dev/null' >> /tmp/oldcron  

4) modify your crontab
crontab /tmp/oldcron

bye
0
 

Expert Comment

by:aurelio
Comment Utility
Also , you can put it in the crontab by the following method , supposing you are using a standard sysV unix :

1) Create a shell script with the find code, e.g.
echo 'find / -ctime 21 -print -exec mv /newdir {} \;'>/home/er.sh

2) list the crontab file , using
crontab -l > /tmp/oldcron

3) insert a new line ; this one launches the script every half hour ; modify according to needs
echo '28,01 * * * * /usr/bin/sh /home/er.sh 1>/dev/null 2>/dev/null' >> /tmp/oldcron  

4) modify your crontab
crontab /tmp/oldcron

bye
0
 

Author Comment

by:nadia
Comment Utility
thanks!

The move method works but nothing happens
with "cd /home/html/geo/Archive; find . -type f -ctime +120 -print -exec rm {} \; >> Deleted.Logfile 2>&1

whats wrong? it finds the files but it does not delete them


0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Ever wondered how to display how many visitors you have online. In this tutorial I will show you an easy but effective way to display the number of online visitors in WhizBase. In this article I assume you have read my previous articles and know …
This article will show, step by step, how to integrate R code into a R Sweave document
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now