Skip to main content
  1. Posts/

Asterisk test calls from the CLI

·3 mins

I know this is a little off-topic for a Cisco blog but anyway, whilst I am learning some voice stuff I may post something related from time to time.

I have recently been having some issues with my home Asterisk box where even though there are no connection drops to my home internet connection after some time the SIP trunk between my Asterisk box and my SIP provider ( would drop and go into the state of UNREACHABLE and the only way I could get it to come back up would be to reboot the box.

There is no pattern as to when this was happening and the only way to tell would be to either try and make a call (it would just give the busy signal, or just die) or to check on the asterisk command line, this also meant that if people were trying to contact me whilst the trunk was down they would just me welcomed by a ‘the number you have called is not in-service’ message.

One thing that did seem to help is making sure that there are regular calls in/out of the box but this meant manually calling to/from the VoIP system and I always seem to forget.

I looked into several options and then discovered the magic that is the Asterisk spool directory, you can place a call file into the outgoing spool directory and as long as the file modification date is not in the future it will instantly run said call file.

What I have done is set up a bash script to run every 30mins to call a pre-determined test number at my sip provider and play a ‘hello world’ message.

The script for this is as follows:


DATE=<code>date +%d%m%Y-%H%M</code>

echo "Channel: SIP/Sipgate/10000" >> /tmp/$FILENAME
echo "Application: Playback" >> /tmp/$FILENAME
echo "Data: hello-world" >> /tmp/$FILENAME
echo "MaxRetries: 2" >> /tmp/$FILENAME
echo "RetryTime: 30" >> /tmp/$FILENAME
echo "Archive: Yes" >> /tmp/$FILENAME

chown asterisk:asterisk /tmp/$FILENAME
mv /tmp/$FILENAME /var/spool/asterisk/outgoing/

Every time this script is ran it creates the call file to call 10000 (the test number) and then move it to the spool directory. The Archive option in the call file means that once the call has been made it will be moved to the outgoing_done directory in the spool and it appends to the file whether the call was successful or if it failed.

My plan is to create another bash script that checks through the call files and if there is more than 2 failures will reboot the box and email myself to let me know that it has happened so that I can check everything is ok.

If anyone else has any ideas as to what could be causing the trunk issue please let me know.