Link to home
Start Free TrialLog in
Avatar of nadia
nadia

asked on

cron job to move old files to another directory

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
ASKER CERTIFIED SOLUTION
Avatar of ke4fom
ke4fom

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of aurelio
aurelio

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
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
Avatar of nadia

ASKER

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