Run shell script

Hi
I am not able to run a shell script. My extensions.conf looks like this:

        ; *** DOORBELL INCOMING ***;
        exten => 111,1,SIPAddHeader("Alert-Info:doorbell")      ; Doorbell Ringing Tone
;       exten => 111,1,SIPAddHeader("Alert-Info:Harmonize")     ; Doorbell Ringing Tone
        exten => 111,n,System(!sudo -uasterisk /usr/share/asterisk/agi-bin/doorcall.sh)
        exten => 111,n,Dial(SIP/13&SIP/16)                      ; Call listed clients

And doorcall.sh looks like this:

#!/bin/sh
IP_LOXONE=192.168.2.30
PORT_LOXONE=7400
ID_CALL=19

echo -n $ID_CALL | nc -4u $IP_LOXONE $PORT_LOXONE

However, when I call "!sudo -uasterisk /usr/share/asterisk/agi-bin/doorcall.sh" in the CLI it works perfect. What do I missing?

There is a bogus “!”.

You haven’t given the full path to sudo.

You haven’t given the full path to nc (although sudo might handle that).

I would suggest it was completely reasonable for sudo to refuse to work in a a batch context like this, but I don’t know that that is actually the case. If Asterisk is running as root, use su.

I don’t see why that script would even need to run as root.

It’s not running it as root, it is trying to run it as asterisk using an obscure option on sudo.

How do I provide the full path?

Please read up on Unix (Posix) filneames.

I think it is not a problem with the path. I exchanged !sudo with /usr/bin/sudo and I also tried to skip the script file and directly run the netcat command. and it also does not work.

extensions.conf

        ; *** DOORBELL INCOMING ***;
        exten => 111,1,SIPAddHeader("Alert-Info:doorbell")      ; Doorbell Ringing Tone
;       exten => 111,1,SIPAddHeader("Alert-Info:Harmonize")     ; Doorbell Ringing Tone
        exten => 111,n,System(/usr/bin/sudo -uloxberry /usr/share/asterisk/agi-bin/doorcall.sh)
        exten => 111,n,System(/bin/echo -n -e “${CALLERID(ALL)}” | nc -w 192.168.2.30 7400)
        exten => 111,n,Dial(SIP/13&SIP/16)                      ; Call listed clients

CLI:

    -- Executing [111@local:1] SIPAddHeader("SIP/19-00000021", ""Alert-Info:doorbell"") in new stack
    -- Executing [111@local:2] System("SIP/19-00000021", "/usr/bin/sudo -uloxberry /usr/share/asterisk/agi-bin/doorcall.sh") in new stack
    -- Executing [111@local:3] System("SIP/19-00000021", "/bin/echo -n -e “"VTO2000A_OG" <19>” | nc -w 192.168.2.30 7400") in new stack
    -- Executing [111@local:4] Dial("SIP/19-00000021", "SIP/13&SIP/16") in new stack

Is there something that I am missing?

edit//
I changed the command to this:

        exten => 111,n,System(echo -n 19 | nc -4u 192.168.2.30 7400)
-- Executing [111@local:3] System("SIP/19-00000025", "echo -n 19 | nc -4u 192.168.2.30 7400")

now it is working directly from the extensions.conf. The problem must be how I linked the “/usr/share/asterisk/agi-bin/doorcall.sh” file

Why are you using sudo?

Because I am desperate :frowning:
I tried it this way:

        exten => 111,n,System(/usr/share/asterisk/agi-bin/doorcall.sh)

And it looks like there is no error:

  -- Executing [111@local:1] SIPAddHeader("SIP/19-00000053", ""Alert-Info:doorbell"") in new stack
    -- Executing [111@local:2] System("SIP/19-00000053", "/usr/share/asterisk/agi-bin/doorcall.sh") in new stack
    -- Executing [111@local:3] Dial("SIP/19-00000053", "SIP/13&SIP/16") in new stack

But this script:

#!/bin/bash
IP_LOXONE=192.168.2.30
PORT_LOXONE=7400
ID_CALL=19

echo -n $ID_CALL | nc -4u $IP_LOXONE $PORT_LOXONE
#echo -n 19 | nc -4u $IP_LOXONE $PORT_LOXONE
#echo -n -e 22 | nc -w 192.168.2.30 7400

is not running properly, because I can’t see any UDP activities. But when I run the script from the commandline it works.
Is there a way I can make any CLI outputs from my scriptfile, so I can make sure it is properly working?

I would use ls -lu on the script to see if it actually being read.

Turning up the logging until you see the return code form System (I think it is logged).

Using

: 2> log-file
set -x

To check that the variables are expanding properly and the commands are being read from the script. This will also mean you capture error message.

Add debugging lines to the script, using/bin/echo >&2 to get more information, e.g. command return codes.

1 Like