# Node-red command in linux shell doesn't work in script

**URL:** <https://discourse.nodered.org/t/node-red-command-in-linux-shell-doesnt-work-in-script/62737>\
**Category:** General\
**Created:** [17 May 2022 09:29 UTC](https://discourse.nodered.org/t/node-red-command-in-linux-shell-doesnt-work-in-script/62737 "2022-05-17T09:29:45Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fabien1](https://avatars.discourse-cdn.com/v4/letter/f/f4b2a3/32.png) [@Fabien1](https://discourse.nodered.org/u/Fabien1)\
**Post date:** [17 May 2022 09:29 UTC](https://discourse.nodered.org/t/node-red-command-in-linux-shell-doesnt-work-in-script/62737/1 "2022-05-17T09:29:45Z")

</div>

Hello,

I installed Node-RED on CenOS 7 web server.  
Node-RED works fine, but I happen to reload the Apache server and then Node-RED.

I want to write a script to reload Apache and Node-RED :

```auto
# !/bin/bash
systemctl restart httpd
node-red&
PID=$!
sleep 5
kill $PID
disown -h

```

The problem is the Linux console warns the node-red command is unknown.

What am I doing wrong?

Thanks!

---

<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 May 2022 09:44 UTC](https://discourse.nodered.org/t/node-red-command-in-linux-shell-doesnt-work-in-script/62737/2 "2022-05-17T09:44:11Z")

</div>

I use RaspberryPiOS not CenOS so this may not be available to you, but the NR installation script creates and enables a systemd script.

So I can restart Node-red with **systemctl restart nodered**

ps Does your #! /bin/bash line work with a space between the hash and the bang?

---

<div class="post-metadata">

**Author:** ![Fabien1](https://avatars.discourse-cdn.com/v4/letter/f/f4b2a3/32.png) [@Fabien1](https://discourse.nodered.org/u/Fabien1)\
**Post date:** [23 May 2022 10:31 UTC](https://discourse.nodered.org/t/node-red-command-in-linux-shell-doesnt-work-in-script/62737/3 "2022-05-23T10:31:01Z")

</div>

Hello,

Thanks for your reply!

Apparently, the Node-RED restart works with this command, but with "node-red" instead of "nodered"!

```auto
#!/bin/bash #Yes, there was a space in my last post, but it wasn't in my script!

systemctl restart httpd
systemctl restart node-red
PID=$!
sleep 2
kill $PID
disown -h

```

I have another problem by the way: in this script, I want to kill de $PID because I have to press CTRL+C after the Node-RED restart. The GNU/Linux console replies:

> kill : man kill page  
> line 8 : disown : current : unknown task (not sure about the translation from French)

Any tip?

---

<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:** [23 May 2022 10:53 UTC](https://discourse.nodered.org/t/node-red-command-in-linux-shell-doesnt-work-in-script/62737/4 "2022-05-23T10:53:52Z")

</div>

I had to look up the meaning of $! - it's the PID of the last background process created.  
As far as I can see, your script doesn't create any background processes, though your original version with `node-red&` did.  
This _might_ explain the problem with disown -h too.

So I suggest you get rid of

```auto
PID=$!
sleep 2
kill $PID
disown -h

```

If after doing that you still "have to press CTRL+C after the Node-RED restart", there is something wrong with your systemd script.

Your installation is not standard. Did the "official" installation instructions for CentOS [https://github.com/node-red/linux-installers](https://github.com/node-red/linux-installers) not work for you?  
Did you follow some online tutorial? Why and which one?

---

<div class="post-metadata">

**Author:** ![Fabien1](https://avatars.discourse-cdn.com/v4/letter/f/f4b2a3/32.png) [@Fabien1](https://discourse.nodered.org/u/Fabien1)\
**Post date:** [23 May 2022 11:40 UTC](https://discourse.nodered.org/t/node-red-command-in-linux-shell-doesnt-work-in-script/62737/5 "2022-05-23T11:40:39Z")

</div>

Hello,

Thanks for you reply!

Thinking about the information you provided, I modified the script:

> #!/bin/bash  
> systemctl restart httpd  
> systemctl restart node-red

I loaded the script and, apparently, it worked, with no error message.

---

<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:** [23 May 2022 11:48 UTC](https://discourse.nodered.org/t/node-red-command-in-linux-shell-doesnt-work-in-script/62737/6 "2022-05-23T11:48:27Z")

</div>

Good news 😀

I still think you are storing up trouble for the future by not using the standard installation script.

---

<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:** [22 July 2022 11:49 UTC](https://discourse.nodered.org/t/node-red-command-in-linux-shell-doesnt-work-in-script/62737/7 "2022-07-22T11:49:15Z")

</div>

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