Page 1 of 1

Ownership and rights of files on the Raspberry Pi

Posted: Sunday 16 December 2018 16:29
by DomoticaRob
On my Raspberry PI with Domoticz the files have ‘pi’ as owner and ‘rwxrwxrwx’ as rights.

With a FTP program I can download these files to my local harddisk.

In a dzVents script I make output files. These files have ‘root’ as owner and ‘rw-r-----' as rights.

With a FTP program I CANNOT download these files to my local harddisk.

With the command: ‘sudo chown pi:pi filename’ I can change the owner and then I can download the file. I don’t want to do this every time.

In dzVents I use:

Code: Select all

local file = io.open(fileName, "w+")
io.output(file)
io.write("—Some strings— " .. item.name .. "\n")
io.write("—Some strings— " .. etcetera .. "\n")
io.close(file)
How can I make in dzVents output files with the proper ownership and rights?

Re: Ownership and rights of files on the Raspberry Pi

Posted: Sunday 16 December 2018 17:47
by waaren
Add this to your code

Code: Select all

 local fileName = "your file name"

        local function osExecute(cmd)
            local fileHandle     = assert(io.popen(cmd, 'r'))
            local commandOutput  = assert(fileHandle:read('*a'))
            local returnTable    = {fileHandle:close()}
            return commandOutput,returnTable[3]            -- rc[3] contains returnCode
        end

        
        local result, restultCode = osExecute("sudo chown pi:pi " .. "'" .. fileName .. "'" )
        result = osExecute("ls -l "   .. " '" .. fileName .. "'" )
        print (" rc: [" .. restultCode .."] " .. "result = " .. result  )

Re: Ownership and rights of files on the Raspberry Pi

Posted: Sunday 16 December 2018 19:21
by DomoticaRob
Super!

I don't understand the code, but is works!

Thank you very much.

I'm going to try to expand the code I use for the file output of the attributes of one device to do it for all the devices at ones. That will be a nice exercise.

Have a nice day.

Re: Ownership and rights of files on the Raspberry Pi

Posted: Sunday 16 December 2018 22:40
by waaren
DomoticaRob wrote: Sunday 16 December 2018 19:21 I don't understand the code, but is works!
Please state the lines / statements that you don't understand and I will try to clarify. The whole idea of sharing these code snippets is to make forum member aware what is possible and without understanding, that purpose will not be achieved.

Re: Ownership and rights of files on the Raspberry Pi

Posted: Tuesday 18 December 2018 12:03
by DomoticaRob
Hey Waaren,

You're right. Teaching and learning, that's whats it's all about.

For now I have a couple of very busy day's. Next week, I will look to the snippet, try to find out how and why and come back to you.