Linux terminal through exec node

Hi,

I'm looking for a way to enter command line from node red to the terminal of my linux pc.I was looking online and i found that the node exec would do the trick.

The command line i want to use for a example is: influxd backup -portable /tmp/backup_ex
It works if i directly enter this in my terminal. And for this instruction you don't need to enter your pasword. This is why i choose this instruction as a first step.

I did unclicked the append msg.payload as suggested online.
But i keep getting the error: /bin/sh: 1: influxd: not found

So i'm wondering because the error say that it did not find a directory that this is not the node i am looking for. And this node starts a program or i'm i wrong?

And if so wich node can i use?

Thanks at advance,
Kind regards!
Ward

PS: the code of the node:

[{"id":"b703d18a.ec6b1","type":"exec","z":"3263073.a348778","command":"influxd backup -portable /tmp/backup_ex","addpay":false,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"Backup InfluxDB","x":400,"y":160,"wires":[[],["24aa3131.cf9eae"],[]]}]

you will need to fully qualify the path to the command. so outside of Node-RED type which influxd - then use that full path to the command in the exec node.

1 Like

Oke i send the location with it: /usr/bin influxd backup -portable /tmp/backup_ex

But now i get the error:/bin/sh: 1: /usr/bin: Permission denied
But i've got no pasword on my InfluxDB account? And if i did how do you send the pasword with it?

I was too quick to reply. My apologies for that.

But after searching a little more i think it's because the files in linux (Influxd in my case) doesn't have the right permission settings. Only the root user can ask it and in the terminal you are the root user but not through node red. Is this correct what i'm thinking?

I think you have missed a slash, it should be /usr/bin/influxd

Hi kuema
I first did it with the slash but then he did not find the file so i think you don't need to write it because he will else expect another folder and not a application file.

But i could be wrong.

The slash is required for an absolute path. Otherwise the exec node tries to start /usr/bin, which is a directory, not a file.

You have to use the exact output of which influxd.

Thanks for the reply kuema

In the next screenshot you find the right path

So if i write: /usr/bin/influxd backup -portable /tmp/backup_ex
It should be working then, no? So what i'm i missing then?

Yes, but you'd have to execute it as the correct user as well. That user needs the permission to access Influx' data files.

However, I'm not sure how the backups are created in newer versions, maybe that's no longer valid, if backups are done by the Influx service.

Offline backups seem to be deprecated, so it should be working.

It works if i use the command line in the linux terminal.

But how do you execute it in node red as the right user?

Can you export a mini-flow just consisting of an inject node, the exec node, and debug nodes showing the result and post it here please, then we can try it ourselves.

@Colin Off course here it is:

[{"id":"3263073.a348778","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"b703d18a.ec6b1","type":"exec","z":"3263073.a348778","command":"/usr/bin/influxd backup -portable /tmp/backup_ex","addpay":false,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"Backup InfluxDB","x":400,"y":160,"wires":[[],["24aa3131.cf9eae"],[]]},{"id":"ccd5cf5a.1847d8","type":"inject","z":"3263073.a348778","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":100,"y":160,"wires":[["b703d18a.ec6b1"]]},{"id":"24aa3131.cf9eae","type":"debug","z":"3263073.a348778","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":740,"y":140,"wires":[]}]

And here is my debug screen

Well that is very odd, the error is saying that it cannot find /usr/bin/influxd, and your flow works for me.
What do you see if you run, in a terminal
ls -l /usr/bin/influxd
also put that command in the exec node and run it. Put a debug node on output 1 so you can see what is in the payload.
Can I just check that the terminal you are running the command in is connected to the machine running node red, not the one running the browser (if that is different).

hi Colin

I have run the code in the terminal and the result is.
ward@ward-VM:~$ ls -l /usr/bin/influxd
-rwxrwxrwx 1 root root 68710254 Feb 7 07:56 /usr/bin/influxd

I have to say i thought it had something to do with my File permission so i changed it to chmod 777 as you can see. But still the same error

For the result in Node Red you can see below

How did you install node-red? Are you running it in Docker or a snap or something? It appears it doesn't have full access to the operating system. Also I note that he terminal might be running in a VM. That could also be significant. Is it the same VM that node-red is running in?

i installed it through snap. And i am running it in a VMware but the node red is also opened (and installed) in the same VMware.

That, I am sure, is the issue. Snaps do not have full access to the OS, you have to specifically give them the permissions they need. I don't know how to do that. Unless you have a good reason to use the snap then I suggest doing a regular install. If it is a Debian based system such as Ubuntu you can use the install script from the docs. It mostly reference the Pi but it works fine with Ubuntu too.
https://nodered.org/docs/getting-started/raspberrypi

Ooh oke that's explain alot thanks.
I installed it on a linux mint but i will reinstall it then and try it again.

Once again a big thanks!

The script should work on Mint too. Take the snap out first.