Solved

cron job to move old files to another directory

Posted on 1997-12-09
4
271 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Introduction:   Welcome to my first article ever. To begin with, the reason I write this article.  I participated in a question on Experts Exchange about the start command in Windows and there were some discussion about the usage. The discussio…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

690 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