# How to run script from node-red?

**URL:** https://discourse.nodered.org/t/how-to-run-script-from-node-red/32828
**Category:** General
**Created:** [13 September 2020 18:08 UTC](https://discourse.nodered.org/t/how-to-run-script-from-node-red/32828 "2020-09-13T18:08:03Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Zerg](https://avatars.discourse-cdn.com/v4/letter/z/6de8d8/32.png) [@Zerg](https://discourse.nodered.org/u/Zerg)
#### Post date: [13 September 2020 18:08 UTC](https://discourse.nodered.org/t/how-to-run-script-from-node-red/32828/1 "2020-09-13T18:08:04Z")

</div>

I have a simple script that restarts the zigbee2mqtt.service  
The script is located on "Orange pi zero" where is installed the "Node -red".  
code of script

```auto
#!/usr/bin/env bash

systemctl restart zigbee2mqtt

```

But I can't run the script.  
my flow

```auto
[{"id":"2f448a0f.d879a6","type":"tab","label":"Flow 3","disabled":false,"info":""},{"id":"4cc56c86.93ae84","type":"exec","z":"2f448a0f.d879a6","command":"systemctl restart zigbee2mqtt","addpay":true,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"Restart zigbee2mqtt","x":570,"y":200,"wires":[["a023a041.f66a3"],["a023a041.f66a3"],["a023a041.f66a3"]]},{"id":"9877c52a.07c6e8","type":"inject","z":"2f448a0f.d879a6","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":310,"y":200,"wires":[["4cc56c86.93ae84"]]},{"id":"a023a041.f66a3","type":"debug","z":"2f448a0f.d879a6","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":850,"y":200,"wires":[]}]

```

Also I tried like that

```auto
[{"id":"2f448a0f.d879a6","type":"tab","label":"Flow 3","disabled":false,"info":""},{"id":"4cc56c86.93ae84","type":"exec","z":"2f448a0f.d879a6","command":"/home/zerg/.scrtipts/restart_zigbee2mqtt.sh","addpay":true,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"Restart zigbee2mqtt","x":570,"y":200,"wires":[["a023a041.f66a3"],["a023a041.f66a3"],["a023a041.f66a3"]]},{"id":"9877c52a.07c6e8","type":"inject","z":"2f448a0f.d879a6","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":310,"y":200,"wires":[["4cc56c86.93ae84"]]},{"id":"a023a041.f66a3","type":"debug","z":"2f448a0f.d879a6","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":850,"y":200,"wires":[]}]

```

What am I doing wrong?

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [13 September 2020 18:39 UTC](https://discourse.nodered.org/t/how-to-run-script-from-node-red/32828/2 "2020-09-13T18:39:37Z")

</div>

I think that would need to run as root as it is a system type command.

---

<div class="post-metadata">

### Author: ![Zerg](https://avatars.discourse-cdn.com/v4/letter/z/6de8d8/32.png) [@Zerg](https://discourse.nodered.org/u/Zerg)
#### Post date: [13 September 2020 18:50 UTC](https://discourse.nodered.org/t/how-to-run-script-from-node-red/32828/3 "2020-09-13T18:50:22Z")

</div>

I tried with sudo in node of "exec" and also in script, doesn't help! Probably i do something wrong.

 ![1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/7/476420f6257fddd825ea1deaa3a7f1c186fe01c1.png)

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [13 September 2020 19:04 UTC](https://discourse.nodered.org/t/how-to-run-script-from-node-red/32828/4 "2020-09-13T19:04:34Z")

</div>

No. If Node-RED is running as a normal user it can’t just call sudo as that is a privilege escalation security issue. There are lots of threads in this forum on how to allow this to happen safely.

---

<div class="post-metadata">

### Author: ![Zerg](https://avatars.discourse-cdn.com/v4/letter/z/6de8d8/32.png) [@Zerg](https://discourse.nodered.org/u/Zerg)
#### Post date: [13 September 2020 20:56 UTC](https://discourse.nodered.org/t/how-to-run-script-from-node-red/32828/5 "2020-09-13T20:56:54Z")

</div>

> [@dceejay](#):
>
> There are lots of threads in this forum on how to allow this to happen safely.

I would be grateful if you will help me or hint how to find a solution!

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [13 September 2020 21:18 UTC](https://discourse.nodered.org/t/how-to-run-script-from-node-red/32828/6 "2020-09-13T21:18:16Z")

</div>

In fairness, this is more an OS question than node red and has been covered here a lot - search this forum.

Perhaps, better still, search Google for "systemctl restart without sudo" first 2 or 3 results have some really good info.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [14 September 2020 07:41 UTC](https://discourse.nodered.org/t/how-to-run-script-from-node-red/32828/7 "2020-09-14T07:41:37Z")

</div>

Also search the forum for visudo which can enable you to use sudo with a command without having to enter a password, so it can be run from an exec node.

---

<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: [13 November 2020 07:41 UTC](https://discourse.nodered.org/t/how-to-run-script-from-node-red/32828/8 "2020-11-13T07:41:48Z")

</div>

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