executing os command

Moderator: leecollings

Post Reply
mrzasa
Posts: 4
Joined: Monday 18 January 2016 23:16
Target OS: Raspberry Pi / ODroid
Domoticz version: 2.3530
Location: Warsaw / Poland
Contact:

executing os command

Post by mrzasa »

question is probalby easy but i cannot overcome problem

here is the script i want to be run

commandArray = {}
if (devicechanged['SWRGB'] == 'On') then
-- for i, v in pairs(otherdevices) do print(i, v) end
os.execute('echo -ne "$(echo fbebfff9950000b959d6 | sed -e 's/../\\x&/g')" | nc -u -w1 192.168.12.24 30977')
end
return commandArray

as You see there are " ' " single quotes in expression so whole line cannot be processed - is there any chance someone tell me how to run it ?

side question:

is there any way to get inside LUA device descryption field ?

Best regards

MR
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: executing os command

Post by Egregius »

Puth your code in a shell script and execute that from lua.
Could also be that your quotes need to be escaped \'
mrzasa
Posts: 4
Joined: Monday 18 January 2016 23:16
Target OS: Raspberry Pi / ODroid
Domoticz version: 2.3530
Location: Warsaw / Poland
Contact:

Re: executing os command

Post by mrzasa »

i did try escape - its not working - script runs but nothing happens so i have no idea what went wrong
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: executing os command

Post by Egregius »

Then put the code in a bash script

Code: Select all

#!/bin/bash
echo -ne "$(echo fbebfff9950000b959d6 | sed -e 's/../\\x&/g')" | nc -u -w1 192.168.12.24 30977
and call it by
os.execute('path/script.sh')

make sure script.sh is executable, sudo chmod +x script.sh
alfred_j_kwak
Posts: 110
Joined: Friday 20 September 2013 18:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2.3530
Location: Finland
Contact:

Re: RE: executing os command

Post by alfred_j_kwak »

No. I give up. :)
mrzasa
Posts: 4
Joined: Monday 18 January 2016 23:16
Target OS: Raspberry Pi / ODroid
Domoticz version: 2.3530
Location: Warsaw / Poland
Contact:

Re: executing os command

Post by mrzasa »

Thing is that next step i want is to get rgb from colour picker (or at least try it) so calling external script is not really i seek since its a. slower b. u cant push parameters that easy. Was thinking about lua script that is able to do it.
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: executing os command

Post by Egregius »

This doesn't work either?
And why would that be slower? Quite sure you can't measure the milliseconds difference.

Code: Select all

#!/bin/bash
RGB="$1"
echo -ne "$(echo $RGB | sed -e 's/../\\x&/g')" | nc -u -w1 192.168.12.24 30977
and call it by
os.execute('path/script.sh fbebfff9950000b959d6')
mrzasa
Posts: 4
Joined: Monday 18 January 2016 23:16
Target OS: Raspberry Pi / ODroid
Domoticz version: 2.3530
Location: Warsaw / Poland
Contact:

Re: executing os command

Post by mrzasa »

Ye last night i did that, and works quite nice. Thing is its not only a colour - the whole string is hex and contains few other parameters like MAC address, ip etc. (viewtopic.php?f=51&t=7957#p57175)
I was thinking that those could be put in description of device (switch or rgb switch) so u could have 1 script that works with all of them.
That's why i put "side question" :)
Anyway method You gave here works so thank You for Your effort :)
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: executing os command

Post by Egregius »

You can sent multiple arguments to the script:

Code: Select all

#!/bin/bash
RGB="$1"
IP="$2"
PORT="$3"
echo -ne "$(echo $RGB | sed -e 's/../\\x&/g')" | nc -u -w1 $IP $PORT
and call it by
os.execute('path/script.sh fbebfff9950000b959d6 192.168.12.24 30977')[/quote]
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest