Page 1 of 1
executing os command
Posted: Tuesday 02 February 2016 21:00
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
Re: executing os command
Posted: Tuesday 02 February 2016 21:04
by Egregius
Puth your code in a shell script and execute that from lua.
Could also be that your quotes need to be escaped \'
Re: executing os command
Posted: Tuesday 02 February 2016 21:06
by mrzasa
i did try escape - its not working - script runs but nothing happens so i have no idea what went wrong
Re: executing os command
Posted: Tuesday 02 February 2016 22:00
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
Re: RE: executing os command
Posted: Tuesday 02 February 2016 22:21
by alfred_j_kwak
No. I give up.

Re: executing os command
Posted: Wednesday 03 February 2016 0:30
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.
Re: executing os command
Posted: Wednesday 03 February 2016 2:08
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')
Re: executing os command
Posted: Wednesday 03 February 2016 8:48
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

Re: executing os command
Posted: Wednesday 03 February 2016 9:04
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]