Sponsor: VoiceMeUp - Corporate & Wholesale VoIP Services

VoIP Mailing List Archives
Mailing list archives for the VoIP community
 SearchSearch 

[asterisk-users] System() command refuses to execute bash script


 
Post new topic   Reply to topic    VoIP Mailing List Archives Forum Index -> Asterisk Users
View previous topic :: View next topic  
Author Message
viljoens at verishare....
Guest





PostPosted: Mon Mar 02, 2015 9:27 am    Post subject: [asterisk-users] System() command refuses to execute bash sc Reply with quote

Hi All

I'm using this extension to try and get Asterisk 1.8.11.0 to run a bash
script:

exten=>802,n,System(/bin/sh -f /root/wireless.sh)

This file is

-rwxr-xr-x 1 root root 171 Mar 2 16:23 wireless.sh

e.g. root owns the file, and it has execute permissions for all users.

Asterisk runs as root as well.

Asterisk executes the command without any errors at max verbosity.

The file wireless.sh contains:

#!/bin/bash
touch wireless-executed

In my /root folder however, the file

wireless-executed

is never written - indicating the script does not execute, even though it is
owner by the same user asterisk runs as, and is world-executable.

How can I use System to run a bash script?

Thanks!

Regards

Stefan


--
_____________________________________________________________________
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
http://lists.digium.com/mailman/listinfo/asterisk-users
Back to top
kevin.larsen at pionee...
Guest





PostPosted: Mon Mar 02, 2015 9:33 am    Post subject: [asterisk-users] System() command refuses to execute bash sc Reply with quote

asterisk-users-bounces@lists.digium.com wrote on 03/02/2015 08:27:07 AM:

Quote:
From: "Stefan Viljoen" <viljoens@verishare.co.za>
To: <asterisk-users@lists.digium.com>,
Date: 03/02/2015 08:27 AM
Subject: [asterisk-users] System() command refuses to execute bash script

Quote:
How can I use System to run a bash script?

Just to rule out some weird permissions issue, try to write the file to some directory that has full read/write permissions to everyone (eg 777). If the file can be written to that directory you probably have a permissions issue still. I run my asterisk under the asterisk user and have it kick of scripts that write to a folder on the system all the time. The folder has full permissions for the Asterisk user.

Give it a shot and see what you get.
Back to top
viljoens at verishare....
Guest





PostPosted: Mon Mar 02, 2015 9:45 am    Post subject: [asterisk-users] System() command refuses to execute bash sc Reply with quote

Hi all

I got this solved.

Turns out the script WAS executing, but I forgot that apparently you need to
follow "cron rules" in any BASH scripts executed via System() from an
Asterisk dialplan.

E. g. all paths must be fully and absolutely specified, there are no
relative path references available.

So I changed the the file wireless.sh which was:

#!/bin/bash
touch wireless-executed

to

#!/bin/bash
touch /root/wireless-executed

and now if I phone 800 on my Asterisk context I can see that the file

wireless-executed

is created by the touch binary, which indicates that Asterisk has run the
script successfully.

So the problem was not Asterisk or BASH or permissions, but rather that it
appears that all paths in any System() script must be absolutely, not
relatively, specified.

Hope this helps somebody - simply follow "cron rules" when writing
Asterisk-callable BASH scripts which you plan to trigger via the System()
Asterisk dialplan application.

Regards

Stefan


--
_____________________________________________________________________
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
http://lists.digium.com/mailman/listinfo/asterisk-users
Back to top
tzafrir.cohen at xorco...
Guest





PostPosted: Mon Mar 02, 2015 10:28 am    Post subject: [asterisk-users] System() command refuses to execute bash sc Reply with quote

Hi,

Some notes,

Don't run Asterisk as root.

But also:

On Mon, Mar 02, 2015 at 04:44:48PM +0200, Stefan Viljoen wrote:
Quote:
Hi all

I got this solved.

Turns out the script WAS executing, but I forgot that apparently you need to
follow "cron rules" in any BASH scripts executed via System() from an
Asterisk dialplan.

E. g. all paths must be fully and absolutely specified, there are no
relative path references available.

So I changed the the file wireless.sh which was:

#!/bin/bash
touch wireless-executed

to

#!/bin/bash
touch /root/wireless-executed

A variant on:

cd `dirname $0`

can help in such cases.

--
Tzafrir Cohen
icq#16849755 jabber:tzafrir.cohen@xorcom.com
+972-50-7952406 mailto:tzafrir.cohen@xorcom.com
http://www.xorcom.com

--
_____________________________________________________________________
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
http://lists.digium.com/mailman/listinfo/asterisk-users
Back to top
asterisk.org at sedwar...
Guest





PostPosted: Mon Mar 02, 2015 11:02 am    Post subject: [asterisk-users] System() command refuses to execute bash sc Reply with quote

On Mon, 2 Mar 2015, Stefan Viljoen wrote:

Quote:
So the problem was not Asterisk or BASH or permissions, but rather that
it appears that all paths in any System() script must be absolutely, not
relatively, specified.

Not quite.

The 'base' for relative paths would be the 'cwd' (current working
directory) of the Asterisk process.

You can show the cwd for your running Asterisk by:

sudo ls -l /proc/$(pidof asterisk)/cwd

which is a link to the process's cwd.

I suspect if you search your file system ('sudo find / -name
wireless-executed'), you will find 'wireless-executed' -- probably in the
directory shown by the above command.

You can set this in the script that starts Asterisk. I set mine to /tmp/
('cd /tmp/') so I know where any random file access will occur, relatively
speaking.

--
Thanks in advance,
-------------------------------------------------------------------------
Steve Edwards sedwards@sedwards.com Voice: +1-760-468-3867 PST
Newline Fax: +1-760-731-3000

--
_____________________________________________________________________
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
http://lists.digium.com/mailman/listinfo/asterisk-users
Back to top
asterisk.org at sedwar...
Guest





PostPosted: Mon Mar 02, 2015 11:05 am    Post subject: [asterisk-users] System() command refuses to execute bash sc Reply with quote

On Mon, 2 Mar 2015, Tzafrir Cohen wrote:

Quote:
A variant on:

cd `dirname $0`

can help in such cases.

This would yield 'the directory the script lives in' which may be
read-only and is probably not where you want random files created.

--
Thanks in advance,
-------------------------------------------------------------------------
Steve Edwards sedwards@sedwards.com Voice: +1-760-468-3867 PST
Newline Fax: +1-760-731-3000

--
_____________________________________________________________________
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
http://lists.digium.com/mailman/listinfo/asterisk-users
Back to top
asterisk at voipbusine...
Guest





PostPosted: Mon Mar 02, 2015 11:16 am    Post subject: [asterisk-users] System() command refuses to execute bash sc Reply with quote

I'm surprised that you didn't have to specify the full path to the 'touch'
command. When writing AGI scripts, I always do something like
$touch = which( 'touch' ). I guess it's over kill.
John

-----Original Message-----
From: asterisk-users-bounces@lists.digium.com
[mailto:asterisk-users-bounces@lists.digium.com] On Behalf Of Stefan Viljoen
Sent: Monday, March 02, 2015 9:45 AM
To: asterisk-users@lists.digium.com
Subject: Re: [asterisk-users] System() command refuses to execute bash
script

Hi all

I got this solved.

Turns out the script WAS executing, but I forgot that apparently you need to
follow "cron rules" in any BASH scripts executed via System() from an
Asterisk dialplan.

E. g. all paths must be fully and absolutely specified, there are no
relative path references available.

So I changed the the file wireless.sh which was:

#!/bin/bash
touch wireless-executed

to

#!/bin/bash
touch /root/wireless-executed

and now if I phone 800 on my Asterisk context I can see that the file

wireless-executed

is created by the touch binary, which indicates that Asterisk has run the
script successfully.

So the problem was not Asterisk or BASH or permissions, but rather that it
appears that all paths in any System() script must be absolutely, not
relatively, specified.

Hope this helps somebody - simply follow "cron rules" when writing
Asterisk-callable BASH scripts which you plan to trigger via the System()
Asterisk dialplan application.

Regards

Stefan


--
_____________________________________________________________________
-- Bandwidth and Colocation Provided by http://www.api-digital.com -- New to
Asterisk? Join us for a live introductory webinar every Thurs:
http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
http://lists.digium.com/mailman/listinfo/asterisk-users


--
_____________________________________________________________________
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
http://lists.digium.com/mailman/listinfo/asterisk-users
Back to top
tzafrir.cohen at xorco...
Guest





PostPosted: Mon Mar 02, 2015 11:42 am    Post subject: [asterisk-users] System() command refuses to execute bash sc Reply with quote

On Mon, Mar 02, 2015 at 11:15:26AM -0500, Tech Support wrote:
Quote:
I'm surprised that you didn't have to specify the full path to the 'touch'
command. When writing AGI scripts, I always do something like
$touch = which( 'touch' ). I guess it's over kill.
John

You should generally not need a path to commands in /bin / /usr/bin .

If 'which touch' returned it, it's in the path.

--
Tzafrir Cohen
icq#16849755 jabber:tzafrir.cohen@xorcom.com
+972-50-7952406 mailto:tzafrir.cohen@xorcom.com
http://www.xorcom.com

--
_____________________________________________________________________
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
http://lists.digium.com/mailman/listinfo/asterisk-users
Back to top
asterisk.org at sedwar...
Guest





PostPosted: Mon Mar 02, 2015 11:44 am    Post subject: [asterisk-users] System() command refuses to execute bash sc Reply with quote

Please don' top post.

On Mon, 2 Mar 2015, Tech Support wrote:

Quote:
I'm surprised that you didn't have to specify the full path to the 'touch'
command. When writing AGI scripts, I always do something like
$touch = which( 'touch' ). I guess it's over kill.

The AGI process inherits the environment of the parent, Asterisk.

You can set the Asterisk environment in the script that starts Asterisk.

For example:

cd /tmp/
ulimit -n 8192
nice --adjustment=-20\
env --ignore-environment\
HOSTNAME=${HOSTNAME}\
PATH=${PATH}\
$ASTERISK $START_OPTIONS

--
Thanks in advance,
-------------------------------------------------------------------------
Steve Edwards sedwards@sedwards.com Voice: +1-760-468-3867 PST
Newline Fax: +1-760-731-3000

--
_____________________________________________________________________
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
http://lists.digium.com/mailman/listinfo/asterisk-users
Back to top
Display posts from previous:   
Post new topic   Reply to topic    VoIP Mailing List Archives Forum Index -> Asterisk Users All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group

VoiceMeUp - Corporate & Wholesale VoIP Services