Quantcast
Channel: FreePBX Community Forums - Latest posts
Viewing all articles
Browse latest Browse all 226325

Running shell script from within the DialPlan

$
0
0

Hi,

Currently running Asterisk 11.19.0

I am trying to launch an application from the dial plan.
For this instance, I dial 111 to turn on a light and 112 to turn it off, or that is what is supposed to happen.

I have the following in extensions_custom.conf:
[from-internal-custom]
exten=>111,1,Wait(1)
exten=>111,n,System(/home/asterisk/on.sh)
exten=>111,n,System(/usr/local/bin/tdtool --on 1)
exten=>111,n,Verbose(${SYSTEMSTATUS})
exten=>111,n,System(whoami > /home/asterisk/textfile)
exten=>111,n,Verbose(${SYSTEMSTATUS})
exten=>111,n,Hangup()

exten=>112,1,Wait(1)
exten=>112,n,System(/home/asterisk/off.sh)
exten=>112,n,System(/usr/local/bin/tdtool --off 1)
exten=>112,n,Hangup()

the file /home/asterisk/on.sh contains the command /usr/local/bin/tdtool --on 1
same for off.sh

These commands work from the command line as user asterisk.
They run from the Asterisk cli shell command:
!/home/asterisk/on.sh

When the dial plan is parsed and the exten is called the logs show:

-- Executing [111@from-internal:1] Wait("SIP/210-0000008e", "1") in new stack
-- Executing [111@from-internal:2] System("SIP/210-0000008e", "/home/asterisk/on.sh") in new stack
-- Executing [111@from-internal:3] System("SIP/210-0000008e", "/usr/local/bin/tdtool --on 1") in new stack
-- Executing [111@from-internal:4] Verbose("SIP/210-0000008e", "SUCCESS") in new stack
SUCCESS
-- Executing [111@from-internal:5] System("SIP/210-0000008e", "whoami > /home/asterisk/textfile") in new stack
-- Executing [111@from-internal:6] Verbose("SIP/210-0000008e", "SUCCESS") in new stack
SUCCESS
-- Executing [111@from-internal:7] Hangup("SIP/210-0000008e", "") in new stack
== Spawn extension (from-internal, 111, 7) exited non-zero on 'SIP/210-0000008e'
-- Executing [h@from-internal:1] Hangup("SIP/210-0000008e", "") in new stack

and:
-- Executing [112@from-internal:1] Wait("SIP/210-0000008f", "1") in new stack
-- Executing [112@from-internal:2] System("SIP/210-0000008f", "/home/asterisk/off.sh") in new stack
-- Executing [112@from-internal:3] System("SIP/210-0000008f", "/usr/local/bin/tdtool --off 1") in new stack
-- Executing [112@from-internal:4] Hangup("SIP/210-0000008f", "") in new stack
== Spawn extension (from-internal, 112, 4) exited non-zero on 'SIP/210-0000008f'
-- Executing [h@from-internal:1] Hangup("SIP/210-0000008f", "") in new stack

[root@pbx asterisk]# ls -al *.sh
-rwx------ 1 asterisk asterisk 124 Nov 23 22:45 off.sh
-rwx------ 1 asterisk asterisk 123 Nov 23 22:44 on.sh
[root@pbx asterisk]# cat textfile
asterisk
[root@pbx asterisk]#

The step:
"SIP/210-0000008e", "whoami > /home/asterisk/textfile"
is run and the file is updated.

Can anyone please tell me where I am going wrong?

Thanks

Paul


Viewing all articles
Browse latest Browse all 226325

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>