Automated recordings deletion

New to freepbx. I’ve recently started recording my calls on the server. I want them to automatically delete themselves after being stored for a month so I don’t run out of storage space.

Can someone help me out on where I find the cdr table and how I would input a script to do this? I want to view the table atleast so I have an idea on how its stored to even think of writing a script to do this.

Any pointers are helpful

to view all:-

find /var/spool/asterisk/monitor/* -name “*.wav”

to delete older than 30 days:-

find /var/spool/asterisk/monitor/* -name “*.wav” -mtime 30 -delete

1 Like

You just made me delete the recordings for the past 30 days. Thanks A Lot. :frowning:
You need to fix this so that other folks won’t make the same mistake.

Oops , sorry. Corrected my typo. :slight_smile:

1 Like

Hi thanks for the correction.
I tried the command and used 360 instead of 30 to delete older than 360 days but I do not see it deleting anything.
Does the command look for subfolders?
Do you have to run it from a specific directory?
Do you need a plus in front of the number of days?

Thanks.

Never mind, it worked. I just had to refresh.

Hi again

I’ve only just round to trying this…

I’ve run the command find /var/spool/asterisk/monitor/* -name “*.wav” which finds all my recordings.

I then run find /var/spool/asterisk/monitor/* -name “*.wav” -mtime 5 -delete and it doesnt delete anything :frowning:

What am I doing wrong?

Running FreePBX 12.0.40
CentOS 6.5

maybe your version of find does not support -delete,

find --version

and

man find

very old versions might need

-exec rm -f {} ;

instead of -delete

Thanks for the reply

I found this command that works :

find /var/spool/asterisk/monitor/ -type f -mtime +15 -exec rm -f {} ;

And for the cronjob

15 1 * * * find /var/spool/asterisk/monitor/ -type f -mtime +14 -exec rm -f {} ; >/dev/null 2>&1

You should remove the ; from your cron job or it will email every time it finds any such match.

1 Like

I am having the same issue. I have a box running
Asterisk 11.13.0 built by palosanto @ rpmbuild64-2.elastix.palosanto.com on a x86_64 running Linux

I’m looking to have all recordings automatically deleted after 60 days.
The location is var/spool/asterisk/monitor
Then it has all the sub folders of the year/month/day/.wav

I tried dicko’s and senates suggestions but neither seem to be working for me. I verified that cron is running…

[[email protected] ~]# rpm -q vixie-cron
vixie-cron-4.1-81.el5
[[email protected] ~]# /sbin/service crond status
crond (pid 3589) is running…

I’m new at this so if you can tell me as simple as possible it would be great. Thanks for your help.

You can edit cron jobs with

crontab -e -u (user) # where user is likely to be either root or asterisk

you can similarly just list them with crontab -l -u (user)

man crontab

Oh okay, so I have to put the cron job text in crontab? I thought I just typed it as a command.

This is what I got before entering any text.

[[email protected] ~]# crontab -l -u asterisk
28 * * * * /var/lib/asterisk/bin/freepbx-cron-scheduler.php
[[email protected] ~]# crontab -l -u root
no crontab for root

When I tried putting in this string to crontab -e -u root, I get this
[[email protected] ~]# crontab -e -u root
no crontab for root - using an empty one

When I put crontab -e -u asterisk, I get this,
[[email protected] ~]# crontab -e -u asterisk
28 * * * * /var/lib/asterisk/bin/freepbx-cron-scheduler.php
~
~
~
~
~
~
~
~

~
~
"/tmp/crontab.XXXXiXr7QL" 1L, 60C

When I put in, find /var/spool/asterisk/monitor/* -name “*.wav” -mtime 3 -delete, I get this

~
~
search hit BOTTOM, continuing at TOP

I tried this and got the same search hit bottom message…
find /var/spool/asterisk/monitor/* -name “*.wav” -mtime 3 -exec rm -f {} ;

Maybe your distro (Elastix) stores it’s recordings in some other format than .wav or some other place than /var/spool/asterisk/monitor/, you should ask in their forum as the mangle what we are used to here quite severely.

This is the exact directory,

/var/spool/asterisk/monitor/2015/06/06/15/exten-300-303-20150615-111230-1434381150.37.wav

I appreciate the help,

Thats a file not a directory , nonetheless

find /var/spool/asterisk/monitor/ -name “*.wav” -mtime 30

will find files +30 days old from now()

man find

So I enter this after typing crontab -e -u asterisk # ?

When I enter

28 * * * * /var/lb/asterisk/bin/freepbx-cron-scheduler.php
find /var/spool/asterisk/monitor/ -name “*.wav” -mtime 30
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
:wq

I get

crontab: installing new crontab
"/tmp/crontab.XXXX7mqNVN":2: bad minute
errors in crontab file, can’t install.
Do you want to retry the same edit?

I feel like I’m just typing in the string in the wrong place.

Yep all wrong for job 2

Yeah you lost me with that.

Maybe start at

Section 4. Crontab example