Run this nifty Perl script daily or weekly via cron. This will keep your voicemail from overflowing and unknowingly rejecting new voicemail.
#!/usr/bin/perl
#
# Script to expire voicemail after a specified number of days
# by Steve Creel
#
# Directory housing the voicemail spool for asterisk
$dir = "/var/spool/asterisk/voicemail";
# Context for which the script should be running
$context = "default";
# Age (Delete files older than $age days old)
$age = 31;
# Age for unheard messages (Defaults to same age for all messages)
# Set to 0 to not delete unheard messages
$unheardage = $age;
# Delete all files older than $age and $unheardage
# (named msg????.??? to get the audio and txt files,
# but we don't delete greetings or the user's name)
if($age==$unheardage) {
# Save time by doing one find if we're treating everything the same
system('find '.$dir.'/'.$context.' -name msg????.??? -mtime +'.$age.' -exec rm {} \; -exec echo Deleted {} \;');
} else {
# Find everything not in a folder called 'INBOX' and delete it after $age days
system('find '.$dir.'/'.$context.' -path \'*INBOX*\' -prune -o -name msg????.??? -mtime +'.$age.' -exec rm {} \; -exec echo Deleted {} \;');
# If unheardage is set to 0, we won't delete any unheard messages
if($unheardage > 0) {
# Delete things that are in a folder called INBOX after $unheardage days
system('find '.$dir.'/'.$context.' -path \'*INBOX*\' -name msg????.??? -mtime +'.$unheardage.' -exec rm {} \; -exec echo Deleted {} \;');
}
}
# For testing - what number to we start when we renumber?
$start = "0";
# Rename to msg and a 4 digit number, 0 padded.
$fnbase = sprintf "msg%04d", $start;
# Make $dir include the context too
$dir.="/".$context;
Randy,
Thanks for the script, but it’s renaming/deleting busy.gsm and unavail.gsm, under /var/spool/asterisk/voicemail/default/${mailbox}/en. Also, I’m seeing the following error when I run it:
“find: paths must precede expression
Usage: find [-H] [-L] [-P] [path…] [expression]”
I’m using CentOS 5.5 and Asterisk 1.6.2.9 and using the included script under /contrib/scripts. Do I need to change something in the script to make it work and not delete greetings or give errors? If so, please let me know exactly what to do. I’m not too great at perl script.
Thanks,
Chris