Page 1 of 1

problem changing linux file-permissions

Posted: Wednesday 08 March 2023 11:32
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

Re: problem changing linux file-permissions

Posted: Wednesday 08 March 2023 12:03
by BartSr
in addition using command on RaspberryPi commandline ( sudo chmod 777 ' .. 'gas.txt') enables all permissions.

Re: problem changing linux file-permissions

Posted: Wednesday 08 March 2023 16:25
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.

Re: problem changing linux file-permissions

Posted: Wednesday 08 March 2023 16:27
by BartSr
Thanks willwmd.
Will look it up.