Upgrade 3CX to v18 and get it hosted free!

Asterisk cmd Backticks

Author image

Synopsis:

Execute a shell command and save the result as a variable.

Description of application:

Backticks(<VARNAME>|<command>)

<VARNAME> – The name of the variable to be set.
<command> – The shell command to execute; be sure to provide the full path to the command. I used sh, but I think any language will do.

Description of function:

Backticks(<command>)

<command> – Same as above.

Notes

  • *CLI> show application BACKTICKS
  • *CLI> show function BACKTICKS

This application is not distributed as part of Asterisk.

Return value

Returns the resulting string.

Example

  • application:

exten => s,1,BACKTICKS(FOO|/your/path/command.sh) ; sets FOO to result

  • function:

exten => s,1,Set(FOO=${BACKTICKS(/your/path/command.sh ${arg1} ${arg2})}) ; sets FOO to result, I only could get the “function” to take arguments

  • command.sh:

#!/bin/sh
x=0
if [ -e “/some/path/$1/caller-$2.ulaw” ]; then x=1; fi /* see man test for info on the if argument */
echo $x

The above takes two args, checks for the existence of the file, if it exists return 1, else return 0; i.e. the resulting value of foo.

install

Follow his install instructions except:

  1. you may want to save app_backticks.c to /usr/src/asterisk
  2. for his step 3, cd /usr/src/asterisk first and then execute /usr/src/asterisk/contrib/scripts/astxs -install app_backticks.c

This script doesn’t work with asterisk >= 1.8 .

See also



Article Reviews

Write a Review

Your email address will not be published. Required fields are marked *

Required Field. Minimum 5 characters.

Required Field. Minimum 5 characters, maximum 50.

Required field.There is an error with this field.

Required Field.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

There are no reviews for this article. Be the first one to write a review.

Related Posts:

Get 3CX - Absolutely Free!
Link up your team and customers Phone System Live Chat Video Conferencing

Hosted or Self-managed. Up to 10 users free forever. No credit card. Try risk free.

3CX
A 3CX Account with that email already exists. You will be redirected to the Customer Portal to sign in or reset your password if you've forgotten it.