How to solve space in linux path

Hi, ik want to execute a rsync command but it doesn't work because there is a space in the path.

this is source path /media/mediacenter/CANON XF2

this is the command. i have put this line in a template node
rsync -vrhn "{{{payload}}}" /home/mediacenter/rib/out

i get this error

rsync: link_stat "/media/mediacenter/CANON XF2\#012" failed: No such file or directory (2) rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1207) [sender=3.1.3]

suddenly the path becomes /media/mediacenter/CANON XF2\#012

when i put this command is the linux (ubuntu) terminal is works perfectly

rsync -vrhn "/media/mediacenter/CANON XF2" /home/mediacenter/rib/out

Node-RED flow

[{"id":"69a52fe4.a9407","type":"template","z":"9e40285b.9b7068","name":"rsync","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"rsync -vrhn \"{{{payload}}}\" /home/mediacenter/rib/out","output":"str","x":930,"y":800,"wires":[["18e03673.1e340a"]]},{"id":"18e03673.1e340a","type":"exec","z":"9e40285b.9b7068","command":"","addpay":true,"append":"","useSpawn":"false","timer":"60","oldrc":false,"name":"","x":1050,"y":800,"wires":[["5f15ab2.52de154"],["5f15ab2.52de154"],["5f15ab2.52de154"]]},{"id":"5f15ab2.52de154","type":"debug","z":"9e40285b.9b7068","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1210,"y":800,"wires":[]}]

how can i solve this issue?

Have you tried escaping the space?
/media/mediacenter/CANON\ XF2

Add some extra quotes:
msg.payload = "\"/media/mediacenter/CANON XF2\""

I can't because the path is variable i have tried double quotes but is doesnt work

I have tried this in a template node
rsync -vrhn "\"{{{payload}}}\"" /home/mediacenter/rib/out

get this error

Command failed:  rsync -vrhn "\"/media/mediacenter/CANON XF2
\"" /home/mediacenter/rib/out
rsync: change_dir "/home/mediacenter//"/media/mediacenter" failed: No such file or directory (2)
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1207) [sender=3.1.3]

In the flow you posted it's not clear who or what is filling the {{payload}} variable.
In this part you have to set the extra quotes, not in the rsync node.

I don't think it is the space that is causing the problem. Feed the message coming in into a debug node and see us what it says. I suspect there is a new line on the end of the string (#012).

I think it's better to keep the rsync in the exec node and past the rest with a payload to the node.

[{"id":"7df77a3e.03d874","type":"exec","z":"55340790.3abc","command":"rsync","addpay":true,"append":"","useSpawn":"false","timer":"60","oldrc":false,"name":"","x":650,"y":300,"wires":[["75c5a255.f158ac"],["75c5a255.f158ac"],["75c5a255.f158ac"]]},{"id":"75c5a255.f158ac","type":"debug","z":"55340790.3abc","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":810,"y":300,"wires":[]},{"id":"fc716702.e8f6a8","type":"inject","z":"55340790.3abc","name":"","topic":"","payload":"-vrhn \"/media/mediacenter/CANON XF2\" /home/mediacenter/rib/out","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":450,"y":300,"wires":[["7df77a3e.03d874"]]}]

Or if you want for the first path a separate payload.

[{"id":"7df77a3e.03d874","type":"exec","z":"55340790.3abc","command":"rsync","addpay":true,"append":"","useSpawn":"false","timer":"60","oldrc":false,"name":"","x":750,"y":300,"wires":[["75c5a255.f158ac"],["75c5a255.f158ac"],["75c5a255.f158ac"]]},{"id":"75c5a255.f158ac","type":"debug","z":"55340790.3abc","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":910,"y":300,"wires":[]},{"id":"fc716702.e8f6a8","type":"inject","z":"55340790.3abc","name":"","topic":"","payload":"/media/mediacenter/CANON XF2","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":350,"y":300,"wires":[["3f37aa94.e8ad76"]]},{"id":"3f37aa94.e8ad76","type":"function","z":"55340790.3abc","name":"","func":"msg.payload = \"-vrhn \\\"\" + msg.payload + \"\\\" /home/mediacenter/rib/out\"\nreturn msg;","outputs":1,"noerr":0,"x":530,"y":300,"wires":[["7df77a3e.03d874"]]}]

Thank!! this works instead of a funtion node i using the template

[{"id":"7df77a3e.03d874","type":"exec","z":"9e40285b.9b7068","command":"rsync","addpay":true,"append":"","useSpawn":"false","timer":"60","oldrc":false,"name":"","x":810,"y":820,"wires":[["75c5a255.f158ac"],["75c5a255.f158ac"],["75c5a255.f158ac"]]},{"id":"75c5a255.f158ac","type":"debug","z":"9e40285b.9b7068","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":950,"y":820,"wires":[]},{"id":"fc716702.e8f6a8","type":"inject","z":"9e40285b.9b7068","name":"","props":[{"p":"path","v":"/media/mediacenter/CANON XF2","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":490,"y":820,"wires":[["38196e14.7ec612"]]},{"id":"38196e14.7ec612","type":"template","z":"9e40285b.9b7068","name":"command complete","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"-vrhn \"{{{path}}}\" /home/mediacenter/rib/out","output":"str","x":650,"y":820,"wires":[["7df77a3e.03d874"]]}]

Sorry to soon, apparently the problem wasn't the space, i still have the issue. could it be because the path is in an object and that's why it's not going well?

Capture

could the enter arrow may be the problem and results in #012
Capture

Hi @Colin i think you are right. the question is how do I rid of that new line

Capture

The javascript trim() function will do that so in a function node you can do
msg.path = msg.path.trim()
if it is msg.path, I haven't studied the debug closely.
However I would first look at where this comes from and remove the line feed at the earliest point possible, often it is simpler to remove it at the source, or prevent it getting there in the first place.
I was fairly confident it was a new line that was the problem because 012 is octal 012 which is hex 0A which is the line feed character, and a filename should not have a line feed embedded in the name.

1 Like

Thanks @Colin i have solved the problem. I found also this solution to use in a function node.

msg.source = msg.path.replace(/\n/g,"");
return msg;

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.