Stefan Viljoen
2015-Mar-02 14:44 UTC
[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
Tzafrir Cohen
2015-Mar-02 15:28 UTC
[asterisk-users] System() command refuses to execute bash script
Hi, Some notes, Don't run Asterisk as root. But also: On Mon, Mar 02, 2015 at 04:44:48PM +0200, Stefan Viljoen wrote:> 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-executedA variant on: cd `dirname $0` can help in such cases. -- Tzafrir Cohen icq#16849755 jabber:tzafrir.cohen at xorcom.com +972-50-7952406 mailto:tzafrir.cohen at xorcom.com http://www.xorcom.com
Steve Edwards
2015-Mar-02 16:01 UTC
[asterisk-users] System() command refuses to execute bash script
On Mon, 2 Mar 2015, Stefan Viljoen wrote:> 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 at sedwards.com Voice: +1-760-468-3867 PST Newline Fax: +1-760-731-3000
Steve Edwards
2015-Mar-02 16:03 UTC
[asterisk-users] System() command refuses to execute bash script
On Mon, 2 Mar 2015, Tzafrir Cohen wrote:> 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 at sedwards.com Voice: +1-760-468-3867 PST Newline Fax: +1-760-731-3000
Tech Support
2015-Mar-02 16:15 UTC
[asterisk-users] System() command refuses to execute bash script
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 at lists.digium.com [mailto:asterisk-users-bounces at lists.digium.com] On Behalf Of Stefan Viljoen Sent: Monday, March 02, 2015 9:45 AM To: asterisk-users at 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
Tzafrir Cohen
2015-Mar-02 16:41 UTC
[asterisk-users] System() command refuses to execute bash script
On Mon, Mar 02, 2015 at 11:15:26AM -0500, Tech Support wrote:> 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. > JohnYou 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 at xorcom.com +972-50-7952406 mailto:tzafrir.cohen at xorcom.com http://www.xorcom.com
Steve Edwards
2015-Mar-02 16:44 UTC
[asterisk-users] System() command refuses to execute bash script
Please don' top post. On Mon, 2 Mar 2015, Tech Support wrote:> 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 at sedwards.com Voice: +1-760-468-3867 PST Newline Fax: +1-760-731-3000