# Start a system command in exec node in root mode

**URL:** <https://discourse.nodered.org/t/start-a-system-command-in-exec-node-in-root-mode/67839>\
**Category:** General\
**Created:** [17 September 2022 08:35 UTC](https://discourse.nodered.org/t/start-a-system-command-in-exec-node-in-root-mode/67839 "2022-09-17T08:35:46Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![chri-kai-in](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/chri-kai-in/32/67889_2.png) [@chri-kai-in](https://discourse.nodered.org/u/chri-kai-in)\
**Post date:** [17 September 2022 08:35 UTC](https://discourse.nodered.org/t/start-a-system-command-in-exec-node-in-root-mode/67839/1 "2022-09-17T08:35:46Z")

</div>

Hello,

i was searching the forum and found some discussion about exec node and the usage of sudo but that unfortunately didn't help me with my issue:

I have the need to call a command in "sudo su" or root mode within exec node of node red.

Details:  
I have a 5'' DSI TFT touch display from Waveshare on my raspberry pi, for which i want to control the brightness out of node red.

For controlling the brightness Waveshare proposes a call "echo xxx \> /sys/class/backlight//brightness" in root mode, with "xxx" reflecting the level of brightness 0...255.

Generating different levels of brightness, depending on dashboard state - no issue.  
Transferring the brightness level in node red to a system call in "sudo su" mode - stuck.

If i try to access the target file from command line in normal user mode or with "sudo" i get a permission denied error. The same is true, when calling it like this within the exec-node.

I already found out that root mode can be achieved with "sudo su" in command line. If i switch to root mode with "sudo su "first and then call "echo xxx \> /sys/class/backlight//brightness" it works as expected.

Unfortunately i have no clue, how to achieve this within an exec node or node red. I tried "sudo su && echo" as command already, but didn't succeed.

Any idea how i could solve the challenge ? I am really stuck.

Thank You for any input !  
Chris

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [17 September 2022 08:54 UTC](https://discourse.nodered.org/t/start-a-system-command-in-exec-node-in-root-mode/67839/2 "2022-09-17T08:54:19Z")

</div>

Hello @chri-kai-in,

Not really a Node-red issue but still...

I believe the problem is that if you do **sudo echo hello \> filename** , the echo command is executed as root but the redirection (the \> ) is not.

What happens if you run this from the command line?  
**echo xxx | sudo tee /sys/class/backlight/brightness**  
(Obviously use a sensible value instead of "xxx")

If it works, try it via the exec mode.

---

<div class="post-metadata">

**Author:** ![chri-kai-in](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/chri-kai-in/32/67889_2.png) [@chri-kai-in](https://discourse.nodered.org/u/chri-kai-in)\
**Post date:** [17 September 2022 09:03 UTC](https://discourse.nodered.org/t/start-a-system-command-in-exec-node-in-root-mode/67839/3 "2022-09-17T09:03:47Z")

</div>

> [@jbudd](#):
>
> echo xxx | sudo tee /sys/class/backlight/brightness

Hello @jbudd,

Thank You for your quick reply. Your idea works on command line. (i missed a path level in my first unsuccessful tests...). Looks like a more elegant solution than mine below.

I think i found a solution meanwhile myself. So we have two solutions to choose from:

Option 1:

echo "echo xxx \> /sys/class/backlight/\<display-id\>/brightness" | sudo su

In the exec node i distribute the command like the following:

Command: echo "echo  
Append: activate msg.payload  
Additional parameters: \> /sys/class/backlight/\<display-id\>/brightness | sudo su

Option 2:

echo xxx | sudo tee /sys/class/backlight/\<display-id\>/brightness

Command: echo  
Append: activate msg.payload  
Additional parameters: | sudo tee /sys/class/backlight/\<display-id\>/brightness

Both options work, whereas i find @jbudd s solution much more elegant.

So my issue seems solved to me. Hope it helps others with similar challenges.

BR  
Chris

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [17 September 2022 09:14 UTC](https://discourse.nodered.org/t/start-a-system-command-in-exec-node-in-root-mode/67839/4 "2022-09-17T09:14:36Z")

</div>

Ok, that's an ingenious approach.  
I do wonder if the root shell will be left hanging after it's written to the file.

I almost never use sudo su, and definitely not for a background process, it just feels wrong.

By the way, I notice that in your original post your command was  
echo xxx \> /sys/class/backlight//brightness  
So I suggested  
echo xxx | sudo tee /sys/class/backlight/brightness  
But now your command is  
echo xxx \> /sys/class/backlight/display-id/brightness  
So did you test my version with the display id ?

Edit, the forum removed the angle brackets round displayid, so we may have been confusing one another

---

<div class="post-metadata">

**Author:** ![chri-kai-in](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/chri-kai-in/32/67889_2.png) [@chri-kai-in](https://discourse.nodered.org/u/chri-kai-in)\
**Post date:** [17 September 2022 09:16 UTC](https://discourse.nodered.org/t/start-a-system-command-in-exec-node-in-root-mode/67839/5 "2022-09-17T09:16:30Z")

</div>

That's an issue on my side with \< \> brackets need to be prefixed with an "\" to not be parsed in the forum.

An yes my 2nd successful test with the full path did show the expected behavior.

Best Regards  
Chris

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [1 October 2022 09:32 UTC](https://discourse.nodered.org/t/start-a-system-command-in-exec-node-in-root-mode/67839/7 "2022-10-01T09:32:35Z")

</div>

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