Hi Everyone

Hope this can be helpful, I wrote this small script to move files to subfolders depending on the files creation date. The reason was to decrease the amount of files in the asterisk monitoring folders to decrease search times.

First, create the following sub folders in the monitoring folder:
5-10Days
10-20Days
20-30Days
30-60Days
60-90Days
90-180Days
180-270Days
270-360Days

Older

Now let’s create a script file and call it MoveRecordings.sh

Note that the first line removes files smaller than 34b.

### Script Start
find /var/spool/asterisk/monitor/ -size -34c -type f -exec rm -f {} \;

find /var/spool/asterisk/monitor/ -maxdepth 1 -type f -mtime +5 -exec mv {} /var/spool/asterisk/monitor/5-10Days/ \;

find /var/spool/asterisk/monitor/5-10Days/ -maxdepth 1 -type f -mtime +10 -exec mv {} /var/spool/asterisk/monitor/10-20Days/ \;

find /var/spool/asterisk/monitor/10-20Days/ -maxdepth 1 -type f -mtime +20 -exec mv {} /var/spool/asterisk/monitor/20-30Days/ \;

find /var/spool/asterisk/monitor/20-30Days/ -maxdepth 1 -type f -mtime +30 -exec mv {} /var/spool/asterisk/monitor/30-60Days/ \;

find /var/spool/asterisk/monitor/30-60Days/ -maxdepth 1 -type f -mtime +60 -exec mv {} /var/spool/asterisk/monitor/60-90Days/ \;

find /var/spool/asterisk/monitor/60-90Days/ -maxdepth 1 -type f -mtime +90 -exec mv {} /var/spool/asterisk/monitor/90-180Days/ \;

find /var/spool/asterisk/monitor/90-180Days/ -maxdepth 1 -type f -mtime +180 -exec mv {} /var/spool/asterisk/monitor/180-270Days/ \;

find /var/spool/asterisk/monitor/180-270Days/ -maxdepth 1 -type f -mtime +270 -exec mv {} /var/spool/asterisk/monitor/270-360Days/ \;

find /var/spool/asterisk/monitor/270-360Days/ -maxdepth 1 -type f -mtime +360 -exec mv {} /var/spool/asterisk/monitor/Older/ \;
### Script End

Finally schedule a cron job to execute after hours, lets make it 23:00 at night.
# crontab –e

Ener the line:
59 22 * * * sh /usr/sbin/MoveRecordings.sh

Regards
Quentin