1 post / 0 new
rx4change
rx4change's picture
Joined: 2009/10/21
Points: 0

In the spirit of the days, I thought I'd share a quick and dirty script we use for voicemail blasting on MTE. Can be convenient for maintenance notifications or maybe just to wish your customers happy holidays.

At any rate, it is a bit hack-ish and makes some assumptions (VM file format, etc...) about the environment, but may be useful to someone.

In any event, you'll need to create properly formatted msg0000.txt and msg0000.WAV (notice WAV file case and compare to what you use on your install) and then point the script to them. It'll crawl all subfolders and all mailboxes and drop the voicemail in the proper spot.

---- script begin -----

#!/bin/sh
# Script to blast a voicemail message to all users in TL MTE

# Function for eval'ing FN
f () {
eval echo \${$#} | sed -e 's/^0*//'
}

voicemailroot=/var/spool/asterisk/voicemail/
voicemailwav=/var/spool/asterisk/voicemail/msg0000.WAV
voicemailtxt=/var/spool/asterisk/voicemail/msg0000.txt

# Open Main VM Directory
cd $voicemailroot

# Get all Tenants
for i in $(ls -d */);
do

cd ${i%%/}

# Get All Mailboxes
echo Mailboxes for Tenant: ${i%%/}
for k in $(ls -d */);
do
echo Mailbox: ${k%%/}

# Is Mailbox Empty?
if [ -z "`find ${k%%/}/INBOX -type f`" ];
then
#Nothing in Mailbox, just copy into 0 position
echo No Voicemail - Copy File into 0 position
cp $voicemailwav $voicemailroot${i%%/}/${k%%/}/INBOX/msg0000.WAV
cp $voicemailtxt $voicemailroot${i%%/}/${k%%/}/INBOX/msg0000.txt
else
# Stuff in mailbox, figure out what is next message slot
cd ${k%%/}/INBOX
VMLIST=$(ls *.txt | sed 's/msg//' | sed 's/\([0-9]\+\).*/\1/g' | tr '\n' ' ')
newfile=`printf msg%04d $(($(f $VMLIST) + 1))`
echo Voicemail file is $newfile
cp $voicemailwav $voicemailroot${i%%/}/${k%%/}/INBOX/$newfile.WAV
cp $voicemailtxt $voicemailroot${i%%/}/${k%%/}/INBOX/$newfile.txt
fi

# Return to main dir
cd $voicemailroot/${i%%/}

done

cd ..

done