Solved

cron job to move old files to another directory

Posted on 1997-12-09
4
268 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Why You Need a DevOps Toolchain

IT needs to deliver services with more agility and velocity. IT must roll out application features and innovations faster to keep up with customer demands, which is where a DevOps toolchain steps in. View the infographic to see why you need a DevOps toolchain.

Question has a verified solution.

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

Recently I have been answering a lot of questions like this in IT forums that I frequent. The question posed is usually something along the lines of "We have software X installed and need to uninstall it for reason Y" or some other variant of the sa…
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 …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

737 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