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.
domoticz user and sh script command
Moderator: leecollings
-
- Posts: 11
- Joined: Wednesday 24 December 2014 13:23
- Target OS: Raspberry Pi / ODroid
- Domoticz version: beta
- Location: Toulouse, France
- Contact:
domoticz user and sh script command
---------------------------------------
Want more about Domoticz scripts and DiY devices?
Go to ---------- http://mydomotic.blogspot.com
Want more about Domoticz scripts and DiY devices?
Go to ---------- http://mydomotic.blogspot.com
-
- Posts: 550
- Joined: Tuesday 17 June 2014 22:14
- Target OS: NAS (Synology & others)
- Domoticz version: 4.10538
- Location: NL
- Contact:
Re: domoticz user and sh script command
Can you try 'chmod 777 scriptFileName'
Synology NAS, slave PI3, ZWave (Fibaro), Xiaomi zigbee devices, BTLE plant sensor, DzVents, Dashticz on tablet, Logitech Media Server
-
- Posts: 9
- Joined: Wednesday 20 November 2013 13:02
- Target OS: Raspberry Pi / ODroid
- Domoticz version: last
- Location: lille fr
- Contact:
Re: domoticz user and sh script command
hi
may be you have to escape some caracters like % => \%
may be you have to escape some caracters like % => \%
-
- Posts: 11
- Joined: Wednesday 24 December 2014 13:23
- Target OS: Raspberry Pi / ODroid
- Domoticz version: beta
- Location: Toulouse, France
- Contact:
Re: domoticz user and sh script command
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.
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.
---------------------------------------
Want more about Domoticz scripts and DiY devices?
Go to ---------- http://mydomotic.blogspot.com
Want more about Domoticz scripts and DiY devices?
Go to ---------- http://mydomotic.blogspot.com
-
- Posts: 26
- Joined: Sunday 04 October 2015 11:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: France
- Contact:
Re: domoticz user and sh script command
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.
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.
-
- Posts: 11
- Joined: Wednesday 24 December 2014 13:23
- Target OS: Raspberry Pi / ODroid
- Domoticz version: beta
- Location: Toulouse, France
- Contact:
Re: domoticz user and sh script command
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.
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.
---------------------------------------
Want more about Domoticz scripts and DiY devices?
Go to ---------- http://mydomotic.blogspot.com
Want more about Domoticz scripts and DiY devices?
Go to ---------- http://mydomotic.blogspot.com
-
- Posts: 666
- Joined: Thursday 02 October 2014 6:36
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2022.2
- Location: Geleen
- Contact:
Re: domoticz user and sh script command
Yes, every shell works a bit different. Jus google for them
Sh, csh, tcsh, ksh, bash and some more shells exist.
Sh, csh, tcsh, ksh, bash and some more shells exist.
-
- Posts: 26
- Joined: Sunday 04 October 2015 11:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: France
- Contact:
Re: domoticz user and sh script command
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 ...
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 ...
-
- Posts: 666
- Joined: Thursday 02 October 2014 6:36
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2022.2
- Location: Geleen
- Contact:
Re: domoticz user and sh script command
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.
For bigger tasks I mostly use perl.
Who is online
Users browsing this forum: No registered users and 1 guest