Moving the call records stored in RAM Asterisk
This article presents an improved script to move files (in this case telephone calls made through Asterisk) unturned open files (calls in progress). It is very typical to have to make recordings of calls from Asterisk in a Call Center for example.
To make this script I used as a base one that I found here, thanks to its author.
Remind before starting what colors mean Applications and Systems:
written texts in the command line: Blue
Output from the command line: Green
File names and file content: Brown
Justification
Asterisk is a telephony software (widely used in VoIP) for building a switchboard with multiple functionalities, including call recording. Normally, for performance, call recordings perform them on a RAM drive, or RAM disk (if you want to know how to create one you can follow this link), then, after certain time intervals, permanently stored on a disk drive, for instance, in a server NAS. Thus, also avoid the deterioration involved in the drive the continuous effort of writing by recording multiple calls.
Of course this is a risk; an electrical fault and recordings are lost. So should save from time to time those recordings in a definite place.
This script I've adapted to my needs. All recordings are saved in a subdirectory that is created every day, with the date thereof, format gsm. The script will initially looking for that subdirectory, he looks into files that are not being used, and finally moved to its final location.
If we did not care to look first if they are being used or not, se podrían mover archivos incompletos, con la pérdida de información que ello supone.
Desarrollo
El script que propongo y que a mí me funciona 😉 es el siguiente:
#!/bin/bash
# Para mover las llamadas grabadas en una unidad RAM
# Revisa el contenido de esa unidad y lo pasa a un disco duro
# tenemos un directorio en esa unidad,
# con subdirectorios que se generan diariamente
## Variables con los directorios a utilizar
RAMDIR="/tmp/discoram"
ALMACEN="/mnt/servidor_almacen" #unidad remota, previamente montada, almacén definitivo
cd $RAMDIR
ls -1d */ > listado.borrable
while read dia #cada línea un directorio diario, se extrae del archivo "listado_borrable"
do # aquí empieza la parte de mover archivos en sí, solo los de sonido formato gsm
for i in $(ls -1 $RAMDIR/$dia/*.gsm) ; do
lsof $ i #comprueba files opened for not moving yet
value = $? #output state, Yes it is 0 the file is open
if [ $value Us 0 ] ; then
if [ -d $ WAREHOUSE / $ day ] ; Then
Echo recordings folder checked
else
mkdir WAREHOUSE / $ day $
#solo creates the folder if necessary
fi
mv $ i $ WAREHOUSE / $ day
fi
done
$ rmdir Day 2> /dev / null # if we delete is empty
done < listado.borrable #aqui ends while
You can download it here if you are more comfortable.
Do not forget to comment and contribute your customized solutions, you can always improve.