Executing bash commands from a sidebar

#1

Hi,

I am developing a sidebar to monitor and manage external server (running locally). I need to execute several different bash commands (ex: ping, java .etc) from my sidebar for monitoring and management tasks. According to my understanding, I am working in the front end browser environment when I am performing tasks from the sidebar but I cannot run bash commands withing the browser environment. I am thinking about a function implemented in the server-side and use it from the frontend. I can implement a function in the node's .js file which is running on the server side and access it from the frontend side of the sidebar. Is this possible, or is there a other way to do this?

Regards,
Malintha

0 Likes

#2

If you need to run things in the runtime, triggered by actions in the browser, then you'll need to expose an admin http api from the runtime that your code in the browser can invoke to trigger the actions.

You can see that in action with the Serial port nodes, where the edit dialog of the Serial node is able to present a list of connected serial devices. It does this by calling a custom admin endpoint the serial node defines that returns the list of connected devices.

For a high level description of how that works, you can read this StackOverflow response: https://stackoverflow.com/questions/41567175/send-data-on-configuration/41567832#41567832

1 Like

#3

Also note you will only execute them at the privilege level that the Node-RED process runs as on the host. This may be ok for monitoring things - but you may need admin or root access to run some admin type commands - in which case the whole of Node-RED will be running at that level - so be careful with security.

1 Like