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
Member Since:
2006-09-27