Executing system commands through Manager API

I know that from the CLI I can user the “!” commando to run any external shell command but when I try to do it from the Manager API using “Command” I cannot get it to work. Cannot erase or modify files I need to go through Asterisk to execute rm or mv.


Action: command
command: !pwd >> /tmp/teste

Response: Follows
Privilege: Command
No such command ‘!pwd >> /tmp/teste’ (type ‘help !pwd >>’ for other possible commands)

How can help me ?

Sorry about my english…

Ramon Lucas

! is handled by the asterisk -r process, not by the main asterisk process (and runs in the security environment of asterisk -r). Even if you use asterisk -c, there is a thread that dose the asterisk -r job.

I think the only way of executing a command through AMI is to run dialplan which uses the System application. This is probably as it should be, as the dialplan can validate the arguments. A direct approach through AMI would be a signficant security risk.

Yes, I put the command system in my dialplan, but the person does not answer the call, the command is not executed. See:

$out = “Action: login\r\n”;
$out .= “Username: admin\r\n”;
$out .= “Secret: 123654\r\n”;
$out .= “Events: off\r\n\r\n”;
$out .= “Action: Originate\r\n”;
$out .= “Channel: Sip/yuiop/$phone\r\n”;
$out .= “Context: calltome\r\n”;
$out .= “Priority: 1\r\n”;
$out .= “Timeout: 30000\r\n\r\n”;
$out .= “Action: Logoff\r\n\r\n”;

exten => s,1,Answer
exten => s,n,Wait(1)
exten => s,n,System(echo test > /tmp/test)
exten => s,n,Background(beep)
exten => s,n,Background(beep)
exten => s,n,Background(sorry-youre-having-problems)
exten => s,n,Background(beep)
exten => s,n,Wait(2)
exten => s,n,Hangup()

Have an idea to help me?

Thank you very much

Local channel, on the source side or change the source code.