Logic Machine Forum
hostname - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: hostname (/showthread.php?tid=963)



hostname - domotiqa - 24.08.2017

Hello, is it possible to have the hostname of the lmachine by script

something like

myname= hostname


RE: hostname - admin - 24.08.2017

Code:
hostname = io.readfile('/proc/sys/kernel/hostname'):trim()



RE: hostname - domotiqa - 25.08.2017

(24.08.2017, 17:37)admin Wrote:
Code:
hostname = io.readfile('/proc/sys/kernel/hostname'):trim()

Heart


RE: hostname - pepe - 14.05.2020

hi, how can i write a hostname by script?

io.writefile...


RE: hostname - Daniel - 14.05.2020

Try this
Code:
------------------------------------
require('uci')
uci.set("system.@system[0].hostname=name63characters")
uci.commit('system')
--------------------------------------



RE: hostname - admin - 14.05.2020

What Daniel posted will work but you will have to reboot for hostname to change. You should also write to hostname file in order to change it right away:
Code:
io.writefile('/proc/sys/kernel/hostname', 'myhostname')



RE: hostname - pepe - 14.05.2020

(14.05.2020, 07:52)Daniel. Wrote: Try this
Code:
------------------------------------
require('uci')
uci.set("system.@system[0].hostname=name63characters")
uci.commit('system')
--------------------------------------

Thank but does not work, maybe it's also me Smile

(14.05.2020, 07:55)admin Wrote: What Daniel posted will work but you will have to reboot for hostname to change. You should also write to hostname file in order to change it right away:
Code:
io.writefile('/proc/sys/kernel/hostname', 'myhostname')


worked but the old name is adopted after a restart Sad


RE: hostname - Daniel - 14.05.2020

I tried it and it worked. Your browser cache?


RE: hostname - admin - 14.05.2020

You need to run both code pieces to set both permanent and current hostname:
Code:
hostname = 'myhostname'

require('uci')
uci.set("system.@system[0].hostname=" .. hostname)
uci.commit('system')
io.writefile('/proc/sys/kernel/hostname', hostname)



RE: hostname - pepe - 14.05.2020

(14.05.2020, 07:52)Daniel. Wrote: Try this
Code:
------------------------------------
require('uci')
uci.set("system.@system[0].hostname=name63characters")
uci.commit('system')
--------------------------------------

sorry it works! thanks forgot a sign...
after the restart it will be kept