Can’t execute cp command to a samba share using nodered

Hello.

I have a problem with a network share an the node-red integration, particularly the exec command.
The command is a very simple copy one:

cp /config/www/cam_captures/ojo_interior.jpg /config/samba/camera/1613148935618.jpg

That is the string that I generate and I pass down to the exec command. If I copy paste that command on the shell it works perfectly, but If I execute the flow it does nothing. No error, the output status is 0, but the file is not copied.
What can be going on here?

The flow is simple as hell:


[
    {
        "id": "a03ab777.710698",
        "type": "debug",
        "z": "f92c309a.afade",
        "name": "hook",
        "active": false,
        "tosidebar": true,
        "console": true,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 930,
        "y": 620,
        "wires": []
    },
    {
        "id": "271f9e23.20b8d2",
        "type": "exec",
        "z": "f92c309a.afade",
        "command": "",
        "addpay": true,
        "append": "",
        "useSpawn": "false",
        "timer": "",
        "oldrc": false,
        "name": "",
        "x": 710,
        "y": 720,
        "wires": [
            [],
            [],
            []
        ]
    },
    {
        "id": "9eeb7fdc.b058e",
        "type": "function",
        "z": "f92c309a.afade",
        "name": "build cmd",
        "func": "const file = msg.file\nconst share = '/config/samba/camera'\nconst d = new Date()\nmsg.payload = `cp ${file} ${share}/${Date.now()}.jpg`\nreturn msg",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "x": 720,
        "y": 680,
        "wires": [
            [
                "271f9e23.20b8d2",
                "efc2f381.93dd3"
            ]
        ]
    },
    {
        "id": "efc2f381.93dd3",
        "type": "debug",
        "z": "f92c309a.afade",
        "name": "exec",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 960,
        "y": 720,
        "wires": []
    }
]

image

Whats the debug from the exec node have ?

you could try putting the output to a file from the linux side "> output.txt"

The output, of all possible outputs is just status: 0, so everything is ok

send the output to a file just to be sure there isnt any output

have you tried running the command as sudo?

Do you mean to add sudo to the command?
The command works on the console (where I run as root)

sudo cp /config/www/cam_captures/ojo_interior.jpg /config/samba/camera/1613148935618.jpg

I would say that its a permission problem.. what user is node-red running under?

I changed the output to be generated like this:


sudo cp /config/www/cam_captures/ojo_interior.jpg /config/samba/camera/1613197057497.jpg 2>/tmp/output.log

And I get an error 127
I'll try the error redirect without sudo.
But, if it were a permissions problem I should see some access denied error or something like that, no?

Yep exactly.

Ok, I think I found the key problem.
The node-red addon runs inside a docker container (this is how it works on hassio).
If I inspect the container, I see it has the following volumes available:

            "Volumes": {
                "/config": {},
                "/data": {},
                "/dev": {},
                "/media": {},
                "/share": {},
                "/ssl": {}
            },

I guess the data is where the "data" is supposed to be mounted.
To check if the problem is that the FS inside the docker container does, or does not, match the out one, I executed the following

docker exec -it addon_a0d7b954_nodered /bin/sh

There, I can check that the origing /config exists and contains all the data that I expect.
The folder where the samba share is mounted, also exists, and guess what? All the files are there.
My understanding is that the share is being mounted as a normal folder, and the data is being copied to the folder inside the container on the local FS, but outside the container what I see are the actual content of the share because it is mounted there.

Note to everyone asking for help on the forum - please make sure that you give ALL of the relevant info.

In particular, we regularly see Docker causing additional confusion and complexity for people, it is key that you let people know the environment that you are using.

1 Like