I am trying to run a .sh script (that sends an image to our database from the device) through our companies admin dashboard. Is there a way to use the SDK to push a bash exec command to a specific container?
For clarity, this is what I am trying to do:
Our admin logs into our dashboard
Our admin want to retrieve an image from the device
Admin clicks ‘Retrieve Image’
Our API connects to Balena SDK and runs ‘./send_image.sh’
The response from ./send_image.sh script is returned to the admin dashboard
Hi @hunter, I don’t think it’s possible to use the SDK to push commands to a device. You could somewhat hack the CLI to achieve part of it though, would that work for you?
Here is what I would do. You can pipe commands to the SSH CLI command: echo "uptime; exit;" | balena ssh <DEVICE_UUID>. This will run uptime on the device’s hostOS, send the result back and exit. If you instead pipe the contents of a script you could run a script that uses balenaEngine to connect to the container from the hostOS and then run a command there. Let me exemplify.
You would need to run:
cat script.sh | balena ssh <DEVICE_UUID>
And your script.sh would look like this:
balena exec -it <CONTAINER_ID> sh -c "uptime; exit;"
exit;
This will run uptime in container <CONTAINER_ID> which is running on device <DEVICE_UUID>.