[asterisk-users] How to run a batch file on the asterisk CLI

Tzafrir Cohen tzafrir.cohen at xorcom.com
Wed Aug 30 22:49:21 MST 2006


On Wed, Aug 30, 2006 at 09:15:56PM -0700, Steve Edwards wrote:
> If you meant "can Asterisk read a series of commands from a file" the 
> answer is no, but something like the following may do:
> 
> 	cat batch-file\
> 		| awk '{printf "/usr/sbin/asterisk -r -x \"%s\"\n", $0}'\
> 		| sh

This is very slow.

A faster option is to use socat and write the commands directly to the
Asterisk socket.

#!/bin/sh

while read line
do 
        echo -n "$line"
        sleep 0.001
done \
| socat STDIN UNIX-CONNECT:/var/run/asterisk/asterisk.ctl


The short sleep is only needed to guarantee that every line is written 
in a separate write() call .

It will not print any output from any command, though, or even report an
error. And you'll have to end your "programs" with a "quit" line.

With some more tweaking one would get a #!-executable...

-- 
Tzafrir Cohen         sip:tzafrir at local.xorcom.com
icq#16849755          iax:tzafrir at local.xorcom.com
+972-50-7952406          jabber:tzafrir at jabber.org
tzafrir.cohen at xorcom.com     http://www.xorcom.com



More information about the asterisk-users mailing list