Voip Phreak

Cool sh!t about Asterisk, VOIP, XMPP 'n stuff

Randomizing your voicemail greetings with Asterisk to annoy friends and family!

| 1 Comment

Do you run Asterisk for your house as well as for your business? Have you ever wanted to play a random voicemail greeting to the house callers? Just so they aren’t always hearing the same thing every time they call? Well, with this little trick you can do it very easily.

First, find yourself some Funny Answering Machine messages or other such thing that you want to rotate around. These will usually come in .wav or .mp3 format, which you’ll have to convert, using information from voip-info on converting from wav to gsm for use with asterisk.

After you’ve converted your files, you can follow these simple steps to get some random voicemail.

First, make a directory for your random voicemail gsm files

# mkdir /var/spool/asterisk/random-vm

Now, copy all your gsm files to this directory

# mv /home/admin/*.gsm /var/spool/asterisk/random-vm

Now, delete your old unavailable messages from your voicemail directory. In this case it’s extension 7000, yours might differ.

# cd /var/spool/asterisk/voicemail/device/7000/
# rm unavail.gsm unavail.wav unavail.WAV busy.gsm busy.wav busy.WAV

Now, create a symlink from busy.gsm to unavail.gsm

# ln -s unavail.gsm busy.gsm

Now you just need to setup a little script to randomize the voicemail greetings.

# cd /var/spool/asterisk/random-vm
# nano vmscript.sh

And using your favourite editor (nano for us.. yes, we’re not that nerdy) paste the following in.


# number of voicemails to rotate is 6 (0-5). Change to match yours.
number=`expr $(date +%S) % 6`

# remove the old voicemail message
rm /var/spool/asterisk/voicemail/device/7000/unavail.gsm

# link the unavailable message to one of the random ones, yo!
ln -s /var/spool/asterisk/random-vm/unavail-$number.gsm /var/spool/asterisk/voicemail/device/7000/unavail.gsm

# done!

Now, exit and save the file. Remember to change the paths, and amount of voicemail greetings as required.

All you should have to do now, is change the permissions, and then add it to cron and you’ll be set.

Change permissions like this

# chown -R asterisk:asterisk /var/spool/asterisk/random-vm
# chmod +x /var/spool/asterisk/random-vm/vmscript.sh

Add it to cron like this

# crontab -e

then add the following line

# to rotate voicemail messages
*/1 * * * * /var/spool/asterisk/random-vm/vmscript.sh

Exit and save your crontab. Which will rotate them every minute. Obviously, if you get like 30 calls a minute you may run into trouble, but for a simple house line, this works great, and always keeps callers guessing!


turns out it wasn’t fully randomizing the messages as I intended. To get this to work, simply change the script above from




and then change

number=`expr $(date +%S) % 6`


number=$(($RANDOM % 6))

Now it’ll rotate as expected.


Author: Voip Phreak

Matt is VOIP phreak!. Matt took an early adoption to telephony as a young BBS user, using pbx's and other fun toys that he could get his hands on to progress eventually into a love of internet telephony. These are his thoughts, views, and little articles about mostly nothing, but something.

One Comment

  1. Too funny, we have done something similar for sales folks who just don’t get the message. And have a specific message for them corresponding to the phone number they use. Lets just say we haven’t heard back from them!

Leave a Reply

Required fields are marked *.