Solved

cron job to move old files to another directory

Posted on 1997-12-09
4
263 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
ID: 1831599
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
ID: 1831600
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
ID: 1831601
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
ID: 1831602
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Autoit restart command not working 6 70
Run command in each subfolder using batch file 7 62
AWS CLI issues with Tags 3 77
Disk Ram Peak 1 43
This tutorial will discuss the log-in process using WhizBase. In this article I assume you already know HTML. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you might look at some of my other articles abo…
This article will show, step by step, how to integrate R code into a R Sweave document
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…

803 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