Asterisk Voicemail Check Disk Usage Script

This latest script was written to prevent 3:00am phone calls. I was recently called because our voicemail server was beginning to run out of disk space. The following script simply scans the voicemail directory, if a user is over 100MB it looks up their extension in the asterisk database and then sends them an email notification to clean it out. Below is the script:

#!/bin/bash
 
#set the maximum disk usage for a user to approx 100MB
size_limit=100000
 
function send_email () {
 
    subject="Voicemail Over Limit"
    message="/tmp/emailmessage.txt.$f"
 
    echo "Hello $name, " > $message
    echo " " >> $message
    echo "This is a notification that your voicemail is currently over the allowed limit.  You are currently using $humansize.  Please either manually delete the voicemails, or you can send an email to patb@codero.com for help with wiping all of the new and saved voicemails in your mailbox." >> $message
    echo " " >> $message
    echo "Thank you," >> $message
    echo "Admin" >> $message
 
    /bin/mail -s "$subject" "$email" < $message
}
 
for f in $(ls /var/spool/asterisk/voicemail/default/)
do
  size=$(du -s /var/spool/asterisk/voicemail/default/$f | awk '{print $1}')
  if [ "$size" -gt "$size_limit" ]
    then
 
        humansize=$(du -sh /var/spool/asterisk/voicemail/default/$f | awk '{print $1}')
        #Query the database for the users email address
        email=$(mysql -u asterisk --password=dbpassword asterisk -e "select email from voicemail_users where mailbox = '$f'")
        #Parse just the email address out of the above query
        email=$(echo $email | awk '{print $2}' )
 
        name=$(mysql -u asterisk --password=dbpassword asterisk -e "select fullname from voicemail_users where mailbox = '$f'")
        name=$(echo $name | awk '{print $2,$3}' )
        #echo "$name    $f  $email  $humansize"
        send_email $email $name $humansize
  fi
    # take action on each file. $f store current file name
done
Comment are closed.

Unfortunately you don't have Adobe Flash-Player.... Klicken Sie hier fü kostenlosen Adobe Flash-Player.