Agent Auto log-off script for Asterisk

Many times an Agent will forget to logoff. This can cause call routing, payroll, and queue statistic problems with Asterisk. With a handy BASH script it is easy to log all the agents out the queues automatically. Below is the shell script and an example of the crontab entry for execution at 6:00 PM every day.


Written by mattb in: Asterisk,Scripts | Tags: , , ,

BASH script to remove files by time

This script removes every *.wav file older then one minute in the directory it is executed.  This script is very useful and can be used with the cron daemon for regular file removal.

find ./*.wav -type f -mmin +1 -exec rm {} \;

Also we can adjust this for days rather than minutes by changing ‘-mmin +1’ to ‘-mtime +10’.  This would delete .wav files in the working directory that were older than 10 days.

find ./*.wav -type f -mtime +10 -exec rm {} \;

One more example,  the script below will erase all MP3 files older than 10 days form Matt’s music directory.  I hope this is of use to someone out there.

find /home/matt/music/*.mp3 -type f -mtime +10 -exec rm {} \;

Written by mattb in: Linux,Scripts | Tags: , , , , , ,

BASH: A simple script to check if a process is running

Scripting is very, very useful.  Don’t make the same mistake I did and wait 5 years into you career to start learning!  In the example below, I’m using the ‘ps -aux’ command piped into grep to determine if a process is still running.  for my example I’m using Firefox, but intend to use this with a Asterisk phone system.  Every minute cron will launch my script to see if Asterisk is still running.  If it is, it will do nothing.  If it isn’t, then it will attempt to restart asterisk and notify the Administrator.  I hope this example helps someone!



#set -x

# Variables Section
# list process to monitor in the variable below.


# varible checks to see if $PROGRAM1
# is running.

APPCHK=$(ps aux | grep -c $PROGRAM1)

# $Company & $SITE variables are for populating the alert email
COMPANY=”VoiceIP Solutions”

# $SUPPORTSTAFF is the recipient of our alert email



# The ‘if’ statement below checks to see if the process is running
# with the ‘ps’ command.  If the value is returned as a ‘0’ then
# an email will be sent and the process will be safely restarted.

if [ $APPCHK = ‘0’ ];


echo mail -s “Asterisk PBX at $COMPANY $SITE may be down” $SUPPORTSTAFF < /dev/null


echo “$PROGRAM1 is running $APPCHK processes” >> asterisk-check.log


echo $APPCHK


Written by mattb in: Linux,Scripts | Tags: , , , , ,

VoiceIP Solutions offers Asterisk PHP GUI for large scale deployments

VoiceIP Solutions
is a Asterisk ‘consulting & deployment’ company in Seattle Washington.  They deploy Asterisk solutions for businesses of all sizes.  From small offices to universities and call centers.  They have sites deployed all over the United States, but mostly on the West Coast.  I’ve been following them for some time; I guess they started deploying Asterisk before 1.2 was released.  I talked to one of their sales rep’s(I think his name was Liam) about the business and wondered if they had done any development work?  He told me that they had done some PHP work for managing larger installs and proceeded to direct me to one of there engineer/developers.



Simple Bash script that copy’s a directory of files and renames them with a Time Stamp

NOTE: I myself am a novice with BASH. I hate scripting, but hey, it’s necessary part of most sysadmin jobs. I came across several hurdles (like changing a name and adding a time stamp in the same loop). I hope this document helps. Please click on my adds, they help pay for the hosting. Thanks and enjoy.



In this scenario I have a customer that I did a custom Asterisk(Open Source PBX) installation for.  They want the capability to backup all voicemails for management to review.  So naturally I made a cron job that copied Asterisk voicemails to a web directory that was htaccess protected.   It seemed to work except I forgot that asterisk copies messages in the format ‘msg001.wav’.

The problem is that if a user erases the messages in his/her mailbox, then the next new incoming voicemail is named ‘msg001’ again. Next, the voicemail gets copied to the web directory and overwrites the original ‘msg001’.  So my challenge is to create a cron job, that copies the new messages and then renames them on the fly with a new name and an appended time stamp.

Every minute the script copies Asterisk voicemail accounts to another arbitrary directory.   Two loops are run on the contents of that directory matching the pattern ‘5???/mess*'(or in Asterisk syntax 5XXX/mess.).  In the case of my customer their VM boxes are all 5XXX(5001,5002,etc..).  The first loops adds a time stamp from when the voicemail was originally created.  The second loop strips ‘message??’ and replaces it with ‘voicemail_’. The result being something like: ‘voicemail_2008-09-15-03:14:09.wav’. I have to change the messages part because if I dont the first loop will add a second time stamp to previously stamped files.

At the end of the script we want to delete the message00?.txt file, because it is not relevent to simply downloading voicemail and may confuse some users. Also we have to change the owner/group to apache so the web server has permission to host the files.

The voicemail are protected with ‘.htaccess’ file, but with some additional work we could make user access based on PAM, LDAP, or MySQL.

Avaya sells voicemail auditing servers for $40,000 per server. But with the Open Source Asterisk PBX and a simple BASH script we can create a comparable system for under $1,000. However this script can be re-purposed for copying and renaming files for any task. Take care.




#set -x

# Variable containing array


# copy files to web directory

#rename those files with a time stamp
for i in $AUDIT ;

do mv $i $i$(date -r $i +%F-%T).wav ;



#strip the ‘messages’ part of the name and replace w/ ‘voicemail’
for i in $AUDIT ;

do mv “$i” “${i/msg????.wav/voicemail_}” ;


# remove any msg????.txt files

rm -rf $MSGFILES

chown -R apache $DIRECTORY2
chgrp -R apache $DIRECTORY2

With Apache, Asterisk and this simple BASH script we have just created a web accessible way to check and back up voicemail!