problem changing linux file-permissions

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
BartSr
Posts: 491
Joined: Sunday 03 July 2016 16:16
Target OS: Raspberry Pi / ODroid
Domoticz version: V2024.7
Location: Netherlands
Contact:

problem changing linux file-permissions

Post by BartSr »

I am struggling to hav a file "pi" permission i.s.o. root.
The aim is to create a textfile holding values of gasmeter. At regular times I want to inspect the content of the file (gas.txt).
But although I used the command : 'sudo chmod 777 ' .. 'gas.txt' it still only has root permissions.
The script is OK but not for changing permissions. What to do?

Code: Select all

return {
	on = {
	
		devices = {
		    913, --switch to force the script to run for testpurpose
		},
	    
		timer = {

			'at 07:00',
			'at 19:00',
			} 
	},
	logging = {
		level = domoticz.LOG_INFO,
		marker = 'BSOtest',
	},
	execute = function(dz, timer)
	  
	    local gasstand = dz.devices(762).counter -- 762 is IDX gasmeter
	    local datetimestamp = tostring(os.date('%Y-%m-%d %H:%M:%S'))
	    file = io.open("/home/pi/gas.txt", "a+")
	    dz.utils.osCommand('sudo chmod 777 '  .. 'gas.txt')
	    file:write(datetimestamp.." gasstand "..gasstand.."\n")
        file:close()
    
    

	end
}

Bart
Raspberry pi 3b
Arduino
KAKU
RfxCom
Zwave2MQTT
OTGW
Chinese sensors temp (Dallas),movement
Tasmota
Esp8266 / 32 espeasy
Zigbee2MQTT
BartSr
Posts: 491
Joined: Sunday 03 July 2016 16:16
Target OS: Raspberry Pi / ODroid
Domoticz version: V2024.7
Location: Netherlands
Contact:

Re: problem changing linux file-permissions

Post by BartSr »

in addition using command on RaspberryPi commandline ( sudo chmod 777 ' .. 'gas.txt') enables all permissions.
Raspberry pi 3b
Arduino
KAKU
RfxCom
Zwave2MQTT
OTGW
Chinese sensors temp (Dallas),movement
Tasmota
Esp8266 / 32 espeasy
Zigbee2MQTT
willemd
Posts: 741
Joined: Saturday 21 September 2019 17:55
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.1
Location: The Netherlands
Contact:

Re: problem changing linux file-permissions

Post by willemd »

When you run it on the command line, it is the user pi that requests and receives root permission, so it works.
When you run it from domoticz, it is probably the user domoticz and if that user is not configured to receive sudo permission, it will not work.
It needs to be maintained in /etc/sudoers. Do a google search for more detail.
BartSr
Posts: 491
Joined: Sunday 03 July 2016 16:16
Target OS: Raspberry Pi / ODroid
Domoticz version: V2024.7
Location: Netherlands
Contact:

Re: problem changing linux file-permissions

Post by BartSr »

Thanks willwmd.
Will look it up.
Raspberry pi 3b
Arduino
KAKU
RfxCom
Zwave2MQTT
OTGW
Chinese sensors temp (Dallas),movement
Tasmota
Esp8266 / 32 espeasy
Zigbee2MQTT
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest