# Run commands in container using balena-cli ssh ?

**URL:** <https://forums.balena.io/t/run-commands-in-container-using-balena-cli-ssh/289036>\
**Category:** Project help\
**Created:** [April 11, 2021, 8:22pm UTC](https://forums.balena.io/t/run-commands-in-container-using-balena-cli-ssh/289036 "2021-04-11T20:22:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ko7eraven](https://avatars.discourse-cdn.com/v4/letter/k/9f8e36/32.png) [@ko7eraven](https://forums.balena.io/u/ko7eraven)\
**Post date:** [April 11, 2021, 8:22pm UTC](https://forums.balena.io/t/run-commands-in-container-using-balena-cli-ssh/289036/1 "2021-04-11T20:22:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rcooke-warwick](https://avatars.discourse-cdn.com/v4/letter/r/ba9def/32.png) [@rcooke-warwick](https://forums.balena.io/u/rcooke-warwick)\
**Post date:** [April 14, 2021, 2:02pm UTC](https://forums.balena.io/t/run-commands-in-container-using-balena-cli-ssh/289036/8 "2021-04-14T14:02:52Z")

</div>

Hi there, thanks for reaching out.

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

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

```

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

```auto
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](https://github.com/balena-io/balena-proxy/issues/466)  
That is currently being worked on.

As a workaround in the meantime, I tried this:

```auto
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:

```auto
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](https://github.com/balena-io/balena-cli/issues/1482#issuecomment-624278963)
