Run commands in container using balena-cli ssh ?

I am trying to use balena-cli to ssh in to a container and run a command. However, this works for the host OS ssh but not for the container shell, when piping a standard input to the balena ssh … command. Is there any way to run a command in the container shell using balena-cli ? I am trying to run a command in the container that pushes specific application logs to the cloud. This is trivial using the balena ssh into the container using cut/paste interactively, but I can’t do this for 50+ devices. Any ideas how to accomplish this ?

Thanks,

Kevin

Hi there, thanks for reaching out.

I tried to reproduce the behaviour you described, and confirmed that:

echo "uptime; exit;" | balena ssh <uuid>

Worked as intended and executed the piped command on the hostOS of my device, but:

echo "uptime; exit;" | balena ssh <uuid> <container_name>

Did not work, and returned nothing.

It turns out that this is a known issue in our balena-proxy component: https://github.com/balena-io/balena-proxy/issues/466
That is currently being worked on.

As a workaround in the meantime, I tried this:

echo "balena-engine ps" | balena ssh <uuid>

Which lists the containers running on the device.
From that, you can get the container NAME of the container that you wish to run a command in, and then use it as follows:

echo "balena exec <NAME> uptime; exit;"; | balena ssh <uuid> 

This is obviously not the most convenient process at the moment, but hopefully could be of use as a temporary workaround. Other suggested workarounds can be found here: allow a command to be specified at the end of `balena ssh` · Issue #1482 · balena-io/balena-cli · GitHub