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: Verde
File names and file content: brown
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.
El script que propongo y que a mí me funciona 😉 es el siguiente:
#!/bin/bash # Para mover las llamadas grabadas en una unidad RAM # Check the contents of that unit and passes it to a hard disk # We have a directory on that drive, # with subdirectories that are generated daily ## Variables with directories to use RAMDIR ="/tmp / discoram" WAREHOUSE ="/mnt / servidor_almacen" #remote unit, previamente montada, almacén definitivo CD $ RAMDIR ls -1 d */ > listado.borrable #cada day while read a daily online directory, It is extracted from the file "listado_borrable" do # Here begins the part of moving files themselves, only sound format 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.