This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Remote script modification
#1
Hi everyone,
 
A lot of questions lately Smile 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
Reply
#2
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:
12345678910111213141516171819202122232425
<? 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
Reply
#3
Wow thank you for your responsiveness ! I'll try this soon and keep you inform.
Thx !
Reply
#4
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 ?
Reply
#5
Add require('apps') to the next line after <?
Reply
#6
That's what I did. Now I have "Error in /www/user/update.lp at line 10: '=' expected near ' if'"
Reply
#7
Post your full code, you probably modified something by accident
Reply
#8
Code:
1234567891011121314151617181920
<? 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 Smile
Reply
#9
Try log variables and check in LM logs what could be the source of problem, like below:

Code:
123456789101112131415161718192021222324252627282930313233
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
Reply
#10
Hi,

If this is your full sample then you miss ?> at the end ..

BR,

Erwin
Reply
#11
Code is fine, ending ?> is optional. Double check .lp file contents on your device.
Reply
#12
(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 ...
Reply
#13
You probably have a non breaking space there, either use another code editor or remove all leading spaces from the code.
Reply
#14
(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:
1234567891011121314151617181920
<? 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:
1234567891011121314151617181920
<? 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
Reply
#15
What you have in "Logs" on Logic Machine when you run this code:

Code:
1234567891011121314151617181920212223
<? 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
Reply
#16
Line 11 is missing comment:
Code:
1
-- reload script/group monitor
Reply
#17
(22.03.2018, 10:45)admin Wrote: Line 11 is missing comment:
Code:
1
-- reload script/group monitor

Angry  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) ?
Reply
#18
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 Big Grin
Reply
#19
You need to use POST request, because GET query string is limited to a certain number of characters
Reply
#20
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
Reply


Forum Jump: