Set exec command with a text input

Hello everybody

I want to insert the value of an "text input" node in an "exec" node.
For example when I put "sudo reboot" in the text input and then click a button, my raspberry pi reboots.

And I don't know how I can easily do this.

Thank you !

That is a rather dangerous thing to do, make sure no-one with evil intent can access the dashboard. But if you must, then in the exec node you can select "Append msg.payload to command" (or something similar, I forget the exact wording) and then leave the command empty. Make sure the command you want is in msg.payload.
I hope you are not running node-red as root, otherwise if someone enters rm -rf / bad things will happen.
[Edit] Even if you are not running as root then something like rm -rf . would also be pretty bad.

1 Like

Note also. If you are not running Node-RED as root then you can't run commands with sudo as that is a privilege escalation. But yes - is a very dangerous thing to do.. I'd advise against it if at all possible.

Thank you, I know the dangers but it isn't a problem for me.

I only want to put the value of my slider or of the text input behind a command and that's why I asked for this.
For example shutdown after x minutes :
shutdown -r +15
15 is the value of the input box

In fact that isn't correct. Using visudo you can specify that defined commands do not need a password when called with sudo, then that command can be invoked from an exec node. I use this to specify that sudo reboot does not need a password so I can reboot the pi if it detects a problem such as network failure, in the hope it will recover. In that case the full command is built into the exec node of course.

In that case configure the exec node with the shutdown command and just append the 15 from the payload.

Yes but I don't know how to insert the payload value in a command
I'm sorry I don't really know how Nodered works

double click on the exec node and read relation to the info panel on the right hand side

Start by using an inject node to inject the injectable bit into the exec node.

I read the info panel but it doesn't help me..
Here is my project, it will probably be easier for you to understand it:


If you don't understand what I am looking for tell me

forget about the dashboard until you understand how Node-RED works.

This is far easier using an inject node or multiple inject nodes