Ownership and rights of files on the Raspberry Pi

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

Moderator: leecollings

Post Reply
DomoticaRob
Posts: 80
Joined: Sunday 29 November 2015 14:03
Target OS: Raspberry Pi / ODroid
Domoticz version: V4.9700
Location: Halle, the Netherlands
Contact:

Ownership and rights of files on the Raspberry Pi

Post 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?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Ownership and rights of files on the Raspberry Pi

Post 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  )
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
DomoticaRob
Posts: 80
Joined: Sunday 29 November 2015 14:03
Target OS: Raspberry Pi / ODroid
Domoticz version: V4.9700
Location: Halle, the Netherlands
Contact:

Re: Ownership and rights of files on the Raspberry Pi

Post 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.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Ownership and rights of files on the Raspberry Pi

Post 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.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
DomoticaRob
Posts: 80
Joined: Sunday 29 November 2015 14:03
Target OS: Raspberry Pi / ODroid
Domoticz version: V4.9700
Location: Halle, the Netherlands
Contact:

Re: Ownership and rights of files on the Raspberry Pi

Post 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.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest