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.

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

something like

myname= hostname
-----------
FRANCE SMARTHOME & SMARTBUILDING INTEGRATION
SE ECO EXPERT
Reply
#2
Code:
hostname = io.readfile('/proc/sys/kernel/hostname'):trim()
Reply
#3
(24.08.2017, 17:37)admin Wrote:
Code:
hostname = io.readfile('/proc/sys/kernel/hostname'):trim()

Heart
-----------
FRANCE SMARTHOME & SMARTBUILDING INTEGRATION
SE ECO EXPERT
Reply
#4
hi, how can i write a hostname by script?

io.writefile...
Reply
#5
Try this
Code:
------------------------------------
require('uci')
uci.set("system.@system[0].hostname=name63characters")
uci.commit('system')
--------------------------------------
------------------------------
Ctrl+F5
Reply
#6
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')
Reply
#7
(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
Reply
#8
I tried it and it worked. Your browser cache?
------------------------------
Ctrl+F5
Reply
#9
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)
Reply
#10
(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
Reply


Forum Jump: