Execute a shell command through the manager connection

Hello,

I’m using Asterisk-Java and would like to execute a shell command from my manager connection.

On the CLI my command works perfectly, but when I use it through the manager connection in my application it doesn’t.
Any other CLI command I use with the manager connection functions, except for the “!”.
Anyone has an idea? Is it maybe due to security purposes? Or is my syntax wrong somewhere?
Is there an alternative way to do this within my application?

This is a snippet of my code:

CommandAction commandAction = new CommandAction("!echo 'hello'");
        CommandResponse response;
//try
            response = (CommandResponse) mc.sendAction(commandAction); //mc is the instance of my manager connection
//catch left out
for (String line : response.getResult())
        {
            System.out.println(line);
        }

and the response I get:

No such command '!echo 'hello'' (type 'core show help !echo 'hello'' for other possible commands)
		echo 'hello'

I also tried asteriskServer.executeCliCommand("!echo 'hello'"); but I still get no positive result.

Thanks.

! is executed in the “asterisk -r” process, not the asterisk server. Everything else is forwarded to the server.

There are ways of executing shell scripts from AMI, but they do require a channel to exist, at least for the duration of the command.

Hi David,

do you have a suggestion for me?

Thanks

Look through the available AMI commands. If I remember correctly, you can use Originate or GetVar.