Bash Script: Dump Asterisk Realtime Voicemail users into Voicemail.conf
I wrote this script while troubleshooting Real Time Voicemail users within Asterisk. This is great if you need to revert back to a flatfile configuration for Voicemail users.
To use the script, simply change the database, username, and password. Enjoy!
#!/bin/bash function get_mailbox { mailbox=$( mysql -u dbuser --password=dbpass asterisk -e "select mailbox from voicemail_users where uniqueid = '$i'") mailbox=`echo $mailbox | awk '{print $2}'` } function get_password { password=$(mysql -u dbuser --password=dbpass asterisk -e "select password from voicemail_users where uniqueid = '$i'") password=`echo $password | awk '{print $2}'` } function get_fullname { name=$(mysql -u dbuser --password=dbpass asterisk -e "select fullname from voicemail_users where uniqueid = '$i'") name=`echo $name | awk '{print $2}'` } function get_email { email=$(mysql -u dbuser --password=dbpass asterisk -e "select email from voicemail_users where uniqueid = '$i'") email=`echo $email | awk '{print $2}'` } function write_file { echo "$mailbox => $password,$name,$email,,attach=yes|saycid=no|envelope=no|delete=no" >> /root/test_dump.txt } for (( i=1; i<=151; i++)) do get_mailbox get_password get_fullname get_email write_file done