Posts: 26
Threads: 2
Joined: Jul 2015
Reputation:
0
12.02.2018, 08:15
(This post was last modified: 12.02.2018, 10:32 by Hippolyte.)
Hi everyone,
A lot of questions lately but this one may be tricky.
We have to update a script on 300 LMs, please tell me there is a simple way to do this remotely … The script name is the same on every LM.
I know there is no API for this but maybe you have another technical solution in your head !
Thank you very much for your help.
Hippolyte
Posts: 7773
Threads: 42
Joined: Jun 2015
Reputation:
447
You can create a custom .lp file that will handle this, to which you must pass name and script get/post variables. Like this: http://LM_IP/user/update.lp?name=test&script=log(event)
For better security you should add some extra password/variable check to this file.
Code: <?
name = getvar('name')
scriptdata = getvar('script')
if name and scriptdata then
item = script.get(name)
if item then
item.script = scriptdata
db:update('scripting', { script = scriptdata }, { id = item.id })
-- save script data to file
script.save(item, true)
-- reload script/group monitor
script.reloadsingle(item)
print('update ok')
else
print('script not found')
end
else
print('invalid arguments')
end
Posts: 26
Threads: 2
Joined: Jul 2015
Reputation:
0
13.02.2018, 11:55
(This post was last modified: 13.02.2018, 11:56 by Hippolyte.)
Wow thank you for your responsiveness ! I'll try this soon and keep you inform.
Thx !
Posts: 26
Threads: 2
Joined: Jul 2015
Reputation:
0
Hello, I have an error when doing exactly what you wrote.
"Error in /www/user/update2.lp at line 5: attempt to index global 'script' (a nil value)"
Can you help me with that please ?
Posts: 7773
Threads: 42
Joined: Jun 2015
Reputation:
447
Add require('apps') to the next line after <?
Posts: 26
Threads: 2
Joined: Jul 2015
Reputation:
0
That's what I did. Now I have "Error in /www/user/update.lp at line 10: '=' expected near ' if'"
Posts: 7773
Threads: 42
Joined: Jun 2015
Reputation:
447
Post your full code, you probably modified something by accident
Posts: 26
Threads: 2
Joined: Jul 2015
Reputation:
0
Code: <?
require('apps')
name = getvar('name')
scriptdata = getvar('script')
if name and scriptdata then
item = script.get(name)
if item then
item.script = scriptdata
db:update('scripting', { script = scriptdata }, { id = item.id })
-- save script data to file
script.save(item, true)
-- reload script/group monitor
script.reloadsingle(item)
print('update ok')
else
print('script not found')
end
else
print('invalid arguments')
end
Here it is
Posts: 940
Threads: 161
Joined: Jul 2015
Reputation:
33
Try log variables and check in LM logs what could be the source of problem, like below:
Code: You can try to log it like this:
<?
require('apps')
name = getvar('name')
scriptdata = getvar('script')
log(1, name, scriptdata)
if name and scriptdata then
item = script.get(name)
log(2, item)
if item then
item.script = scriptdata
log(3, item.script)
res = db:update('scripting', { script = scriptdata }, { id = item.id })
log(4, res)
-- save script data to file
script.save(item, true)
log(5, 'After script.save')
-- reload script/group monitor
script.reloadsingle(item)
print('update ok')
else
print('script not found')
end
else
print('invalid arguments')
end
Done is better than perfect
Posts: 1764
Threads: 6
Joined: Jul 2015
Reputation:
117
21.03.2018, 12:23
(This post was last modified: 21.03.2018, 12:24 by Erwin van der Zwart.)
Hi,
If this is your full sample then you miss ?> at the end ..
BR,
Erwin
Posts: 7773
Threads: 42
Joined: Jun 2015
Reputation:
447
Code is fine, ending ?> is optional. Double check .lp file contents on your device.
Posts: 26
Threads: 2
Joined: Jul 2015
Reputation:
0
21.03.2018, 16:38
(This post was last modified: 21.03.2018, 16:44 by Hippolyte.)
(21.03.2018, 12:41)admin Wrote: Code is fine, ending ?> is optional. Double check .lp file contents on your device.
@admin, I literally copy paste the code of my update.lp file on my device.
Are you sure for the http://LM_IP/user/update.lp?name=test&script=log(event) ?
@Erwin I did add the ?> yet nothing, as admin said it might be optional
@buuuudzik I tried your test and still -> Error in /www/user/update2.lp at line 11: '=' expected near ' log'
I wonder if this is not an issue about the copy paste from this website to the update.lp file. Like invisible caracters coming in the code ...
Posts: 7773
Threads: 42
Joined: Jun 2015
Reputation:
447
You probably have a non breaking space there, either use another code editor or remove all leading spaces from the code.
Posts: 26
Threads: 2
Joined: Jul 2015
Reputation:
0
(21.03.2018, 17:14)admin Wrote: You probably have a non breaking space there, either use another code editor or remove all leading spaces from the code.
Whether I put it perfectly like this
Code: <?
require('apps')
name = getvar('name')
scriptdata = getvar('script')
if name and scriptdata then
item = script.get(name)
if item then
item.script = scriptdata
db:update('scripting', { script = scriptdata }, { id = item.id })
script.save(item, true)
reload script/group monitor
script.reloadsingle(item)
print('update ok')
else
print('script not found')
end
else
print('invalid arguments')
end
?>
Or this
Code: <?
require('apps')
name = getvar('name')
scriptdata = getvar('script')
if name and scriptdata then
item = script.get(name)
if item then
item.script = scriptdata
db:update('scripting', { script = scriptdata }, { id = item.id })
script.save(item, true)
reload script/group monitor
script.reloadsingle(item)
print('update ok')
else
print('script not found')
end
else
print('invalid arguments')
end
?>
I still have " Error in /www/user/update.lp at line 11: '=' expected near 'script'"
when I type http://192.168.1.230/user/update.lp?name...log(event) in Chrome
Posts: 940
Threads: 161
Joined: Jul 2015
Reputation:
33
22.03.2018, 10:19
(This post was last modified: 22.03.2018, 10:59 by buuuudzik.)
What you have in "Logs" on Logic Machine when you run this code:
Code: <?
require('apps')
name = getvar('name')
scriptdata = getvar('script')
log(name, scriptdata) -- THIS CODE LOGS VARIABLES IN LM LOGS
if name and scriptdata then
item = script.get(name)
if item then
item.script = scriptdata
db:update('scripting', { script = scriptdata }, { id = item.id })
script.save(item, true)
-- reload script/group monitor
script.reloadsingle(item)
print('update ok')
else
print('script not found')
end
else
print('invalid arguments')
end
?>
Done is better than perfect
Posts: 7773
Threads: 42
Joined: Jun 2015
Reputation:
447
Line 11 is missing comment:
Code: -- reload script/group monitor
Posts: 26
Threads: 2
Joined: Jul 2015
Reputation:
0
23.03.2018, 14:28
(This post was last modified: 23.03.2018, 14:47 by Hippolyte.)
(22.03.2018, 10:45)admin Wrote: Line 11 is missing comment:
Code: -- reload script/group monitor
I feel so bad ! Sorry for wasting your time and thank you very much all.
It works great !
One last quick question : how do you do a return carriage (new line) ?
Posts: 26
Threads: 2
Joined: Jul 2015
Reputation:
0
Hello, once again thank you for your help.
So it is working really great. Yet I still have this return carriage issue. If I use the http://LM_IP/user/update.lp?name=test&sc...inesscript then the script is written on only one line when I open it on the LM, do you think there is a way to keep the indentation ?
This is for upgrading script on 500 LMs at the same time
Posts: 7773
Threads: 42
Joined: Jun 2015
Reputation:
447
You need to use POST request, because GET query string is limited to a certain number of characters
Posts: 22
Threads: 5
Joined: Jun 2018
Reputation:
0
there is anyway to create the script first? i mean create a script from another script.
If its posible how i make the diferent scripts types?
thanks
|