Page 1 of 1

domoticz user and sh script command

Posted: Wednesday 23 December 2015 16:42
by uNGam3R
Hello all,

I need a linux pro to explain me something weird that happened and that I can't understand.
I have a shell script that:
- retrieves weather information
- speaks (espeak)
- log the information in a virtual text sensor

When I write this to prepare the data (for curl request and espeak command):

speak="Bonjour, aujourd'hui température extérieure $temp degrés. $forecast"
log=${speak// /%20}

The bolded sentence aims to substitute space by %20 for domoticz curl request of virtual text sensor update.
This part is well executed if I'm loged as 'pi' user.
But it is rejected if I try to execute it through a domoticz virtual switch through ON/OFF script action (log returns 512 error)...

Why ?? I can't understand why when I'm logged as pi it's OK and the domoticz user can't go for it...

If I want it to be executed both ways I have to write :
log=`echo $speak | sed 's/ /%20/g'`

Regards
Damien.

Re: domoticz user and sh script command

Posted: Wednesday 23 December 2015 17:42
by pvm
Can you try 'chmod 777 scriptFileName'

Re: domoticz user and sh script command

Posted: Wednesday 23 December 2015 22:02
by dba59
hi

may be you have to escape some caracters like % => \%

Re: domoticz user and sh script command

Posted: Thursday 24 December 2015 9:43
by uNGam3R
It can't be a right problem (chmod 777) as the script is well executed by domoticz when I replace the bolded line by another command.
Same with the escapte caracter, the caracter % is also used in sed command and it works as it...

My guess is that domoticz user (root ?) could have limited rights (seems weird for a root user) to some basic commands or may have different local variables that could causes impossibility to access to some basic commands ...
In both ways, I don't know where to search.

Regards,
Damien.

Re: domoticz user and sh script command

Posted: Thursday 24 December 2015 10:06
by rimram31
Hi,

Do you have start your shell with #!/bin/bash ? The syntax you use ${...} is a bash syntax not a sh one (when echo ... | sed is ok for sh).
Not sure but perhaps the default shell script launch by domoticz is sh and not bash.

Re: domoticz user and sh script command

Posted: Tuesday 29 December 2015 20:24
by uNGam3R
Hello,

I guess you've pointed out something interesting.
Indeed my script begin with #!/bin/sh
However when I run it through ssh I perform a "bash -x script.sh".
I just tried and indeed this bash the problem. By using the tag #/bin/bash it works well.

I'm quite confuse about bash & shell, I was guessing it was the same thing .... Is there somewhere where I can found basic commands for each of these language ?

Regards,
Damien.

Re: domoticz user and sh script command

Posted: Tuesday 29 December 2015 21:18
by jannl
Yes, every shell works a bit different. Jus google for them

Sh, csh, tcsh, ksh, bash and some more shells exist.

Re: domoticz user and sh script command

Posted: Wednesday 30 December 2015 0:37
by rimram31
A little difference for sh, the implementation have to be POSIX compliant, it is a standard (http://pubs.opengroup.org/onlinepubs/00 ... hap02.html) so with minimal features guarantee where other shells have extensions which may differ from one implementation to another. This is in theory because specific sh implementation may have also some extensions and bash become some "de facto" standard (and linux too!).

I'm working for years on several Unix system, the reason why I'm used to work only in sh (and still working exclusively in sh ...) as it give more guarantees that your scripts will work on differents system/environment ... (and also scripts took on the web ...) But this is perhaps not so meaningful today, sh is the poorest shell language with one main missing (internal) string operations, what your script is doing ;)

You explain you want to encode data to be sent with curl, perhaps you can check curl --data-urlencode option which do the job for you (need to be used with -G option as I remember). Don't know how this works with french characters ...

Re: domoticz user and sh script command

Posted: Wednesday 30 December 2015 7:31
by jannl
I know I hurt the feelings of some linux people, but I only use shell scripts for small tasks because of the reasons above.
For bigger tasks I mostly use perl.