Home arrow Linux arrow Asterisk arrow Becoming the Lawnmower Man with Asterisk and Backticks
Becoming the Lawnmower Man with Asterisk and Backticks Print E-mail
Written by Jason   
Feb 20, 2008 at 02:31 PM

If you can overlook the script and copious amount of pseudo-science, the movie Lawnmower Man did have some cool moments. Here's how to become your own Lawnmower Man with Asterisk.

Lawnmower Man Poster 

One of the limitations of Asterisk is the lack of an easy ability to pull something from the real world (ie, a shell script output) to the Asterisk world. Fortunately a third party application/function called Backticks comes in handy for this.

What is it?

Backticks is a third party application/function for Asterisk that allows you to run a shell script and save the results as a variable within Asterisk. This can be really useful if you're trying to be the Lawnmower Man since there isn't an easy way to, let's say, dial every phone at once that's currently registered to the server.

Install it 

The version found on the pbxfreeware site will not work on Asterisk 1.4, but this one will since it's been patched to work with 1.4. Simply drop it in your /usr/src/<asterisk_source_dir>/apps directory and it will be compiled at the same time as Asterisk.

Once you've compiled Asterisk and have it running you should be able to do a show application backticks on the Asterisk CLI to see if it's loaded.

Use it

Let's say you want to dial every phone at once. You'll need a shell script that can pull every phone out into a text file and format it properly so it can be read back into Asterisk:


rm peer*
cd /etc/asterisk
/usr/sbin/asterisk -rx "sip show peers" > peers.txt
sed 's/[ \t]*$//' peers.txt > peers2.txt

#You may need to do some deleting of peers that you don't want called, like VoIP providers

awk '{print $1}' peers2.txt | awk -F \/ '{print $1}' | awk '{gsub(/Name/,"");print}' | awk '/./' > peer_names.txt

for a in $(cat peer_names.txt) ; do echo -n SIP\/$a\& >> peer_reg.txt ; done

sed '$s/.$//' peer_reg.txt > peer_reg2.txt


Save this to a file called worker.sh and make it executable with chmod +x worker.sh . Execute it just to be sure it's doing what you want and check the results with cat peer_reg2.txt .

Now make one more shell script:


cat /etc/asterisk/peer_reg2.txt


Save this and make it executable as well with chmod +x lawnmower.sh .

Now we just need to edit your dialplan to use these scripts with Backticks:


exten => 999,1,Answer()
exten => 999,n,System(/etc/asterisk/worker.sh)
exten => 999,n,Set(LWNMWR=)
exten => 999,n,Backticks(LWNMWR|/etc/asterisk/lawnmower.sh)
exten => 999,n,Dial(${LWNMWR})
exten => 999,n,Hangup()


That's all there is to it. When 999 is dialed it will launch the worker.sh script to get the output ready for Asterisk. The lawnmower.sh script simply outputs the results so Backticks can grab it (I like having them broken up into two files, but it's not a big deal to have worker.sh handle all of it).

If your phones (such as the Linksys SPA-942) support SIPAddHeader you can have them enter into a one way broadcast with Page for an easy to implement intercom system:


exten => 998,1,Answer()
exten => 998,n,System(/etc/asterisk/worker.sh)
exten => 998,n,Set(LWNMWR=)
exten => 998,n,Backticks(LWNMWR|/etc/asterisk/lawnmower.sh)
exten => 998,n,SIPAddHeader(Call-Info: <sip:SERVERNAME>\;answer-after=0)
exten => 998,n,SIPAddHeader(Alert-Info: Ring Answer)
exten => 998,n,Page(${LWNMWR})
exten => 998,n,Hangup()

Replace SERVERNAME with the DNS name of your Asterisk server or the IP address. 

By using SIPAddHeader with the Page application the target phones will all auto answer the call and drop into a one way conference with the caller. Even if a user is on the phone it will put the party they are speaking to on hold and kick on the speaker phone. Great for emergencies.


All and all, Backticks is so very useful it's a shame it isn't part of the regular Asterisk modules.

Any problems? Let me know! 

Last Updated ( Feb 24, 2008 at 03:47 PM )
� http://www.roboguys.com, Mambo and Designed by Siteground