Terminal commands execution using asterisk dialplan

Hi Team,

I want to execute scp command using asterisk dialplan. Can you suggest me any step I can use, as I not being able use System() for doing it.

System is the way. For us to help you , will need to show us what you did, and how it failed.

Hi, I am trying to use this

same => n,System(!/usr/bin/sudo -uec2-user /home/ec2-user/new.sh)

and new.sh contains-
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin/:/home/ec2-user/
#! /bin/sh
scp -r -i CASKeyPair.pem /var/spool/asterisk/monitor/Greeting.pvenkat.1-in.wav ec2-user@10.40.1.**:/var/spool/asterisk/monitor

I have given all permissions to user, for the .sh file, and it is getting perfectly executed from asterisk cli using same command.

Can you please suggest any other way, or something that I am missing out?

I have also tried using
same => n,System(/home/ec2-user/new.sh)
same => n,Verbose(${SYSTEMSTATUS})

and ${SYSTEMSTATUS} returns APPERROR

Remove the “!”. You need to provide details of the error you get.

Hi David,

I am just getting APPERROR continuously on ${SYSTEMSTATUS}, and no other error could be seen.
I have tried by removing !, still the same.
Is there any other approach I should try?

just rum command(/home/ec2-user/new.sh)
is it works?

it does not point but, why do you execute command in asterisk dial-plan?

I have tried that, it is not working as well. I want to send an action to asterisk using AMI, so that it just copies the file to other remote asterisk servers.

After placing logs in my script, I could see that if I normally execute the script from terminal, the logs are properly getting printed in log file, but when the same command is executed via asterisk, nothing is printing in logs. So, I guess asterisk is not being able to access the script properly, and is continuously throwing APPERROR for ${SYSTEMSTATUS}

How can I check whether asterisk is actually accessing the script or not?

Could you show me your script?

if asterisk execute script(command), where is the working directory?
maybe, log issue is caused by this working directory.

how about making simple script?
Like this…


/usr/bin/touch /tmp/script.OK

this is just make a file - /tmp/script.OK

PATH=/home/ec2-user/google-cloud-sdk/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/aws/bin:/home/ec2-user/bin:/home/ec2-user/
#!/bin/bash
exec 1> command.log 2>&1
set -x
#Error function
function die(){
echo “$1”
exit 1
}
PATH=/home/ec2-user/google-cloud-sdk/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/aws/bin:/home/ec2-user/bin:/home/ec2-user/
Host=10.40.1.***
User=ec2-user
#Directory at sent destination
SendDirectory=/var/spool/asterisk/monitor
#File to send at host
FileName=/var/spool/asterisk/monitor/Greeting.coditas3.1-in.wav
#Key file
Key=CASKeyPair.pem

echo “Aperture in Process…”;
ssh-keyscan $Host >> $HOME/.ssh/known_hosts
#The code that will send your file scp
scp -r -i $Key $FileName $User@$Host:$SendDirectory ||
die “@@@@@@@Houston we have problem”

echo “########Aperture Complete#########”;

will try doing that too

Hi…Its working now.
The issue was regarding the directory of the file and user permissions.
Thanks for the assistance.