I would e.g. create a script /usr/local/cleanoldfiles.sh like this:
- Code: Select all
#!/bin/sh
TOPLEVEL=<replace-here-with-top-directory-where-to-delete-files>
MAXDAYS=60
# uncomment only 1st line to test, only second one to remove files
# find $TOPLEVEL -type f -mtime +$MAXDAYS -ls >/tmp/cleanold.log
# find $TOPLEVEL -type f -mtime +$MAXDAYS -exec rm {} \;
Set TOPLEVEL variable and initially, uncomment only the first 'find' line, the one with '-ls' so you can test that it behaves correctly.
Run the command "chmod +x /usr/local/cleanoldfiles.sh" to make it executable
Then, edit /etc/crontab and add a line like the following to run the script e.g. every night at 03:15
15 03 * * * root /usr/local/bin/cleanoldfiles.sh
Finally, run "/usr/syno/etc/rc.d/S04crond.sh stop" and "/usr/syno/etc/rc.d/S04crond.sh start" to restart the cron daemon (to activate your changes in /etc/crontab)
Test to see if it seems to work properly, by running the script and checking in /tmp/cleanold.log that the correct files are candidates for deletion, and if you are happy edit the script again, and uncomment the 'find' line with the '-exec rm'.
That should be all.
