Management of Recordings on Trixbox

jdwebcc
Posts: 149
Member Since:
2006-09-27

Something to contribute -- coming next the script that organizes the files into a file structure --

Here is a small script I have to manage that large monitor folder if your recording all calls like I do.

The script takes four parameters, it was not needed to use a text file. First parameter is the location of the directory to apply the soft quote. The second parameter is the max size of the files in the directory. If the directory is larger than this size, files are deleted starting from the oldest. If you want, you can add two other parameters, an alert size and an email. If the size of the directory is above this alert size, a message is sent to the email specified.

if you run the following command,

/usr/local/bin/dirquota.sh /root/asterisk 17500000 17400000 ldardini@gmail.com

An email will reach me saying the directory is above the alert quota.

If you run the following command,

/usr/local/bin/dirquota.sh /root/asterisk 17400000 17000000 ldardini@gmail.com

Files are deleted until the size shrinks to less than 17400000 KBytes. An alert email will be sent because it is over 17 GB

HERE IS THE SCRIPT -- COPY AND PASTE INTO THE FILE NAME ABOVE

#!/bin/bash

dir=$1
maxsize=$2
alertsize=$3
alertemail=$4

size=`du -s $dir | cut -f 1`

host=`uname -n | cut -d\. -f 1`

if [ "$alertemail" != "" ]; then
if [ $size -gt $alertsize ]; then
echo "The size of the directory $dir is greater than $alertsize. Files will be deleted starting from the oldest ones" | mail -s "WARNING on $host: Space over quota in $dir" $alertemail

fi
fi

while [ $size -gt $maxsize ]; do
echo "Removing older file, size of $size greater than max of $maxsize"
file=`find $dir -type f -printf '%h/%f %T+\n' | sort -k2 | cut -d\ -f 1 | head -1`
echo $file
rm $file
size=`du -s $dir | cut -f 1`
done

Jason S Derr, JDWEB.cc LLC
Creator of ASR Manager -- SOON TO BE MULTI-TENANT

--

Jason S Derr, JDWEB.cc LLC
Creator of ASR Manager



jdwebcc
Posts: 149
Member Since:
2006-09-27
Next Level -- Creating Directory Structure

This is option to allow the storage of the thousands of files that recording calls creates...

Create the file datindir.sh -- make sure to remember to make it executable.. forgot that snipet in the last post.

Then just run it on the folder your storing your recordings.. default is /var/spool/asterisk/monitor

datindir.sh /var/spool/asterisk/monitor

You can cron this job every night to clean up the files --

***********

File contents >>

#!/bin/bash

dir=$1

if [ "$dir" == "" ]; then
echo "Please specify a directory as parameter"
else
files=`find $dir -maxdepth 1 -type f`

for file in $files; do
date=`stat "$file" | grep "Modify" | cut -d\ -f 2 | cut -d- -f 1-2`
mkdir -p $dir/$date
mv $file $dir/$date
done
fi

--

Jason S Derr, JDWEB.cc LLC
Creator of ASR Manager



gweedo
Posts: 23
Member Since:
2007-05-11
Thanks! Fantastic...

Jason... Awesome - thanks for sharing!

Rob G
-=b2b Solutions
FloridaTechServices.com



Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.