# How to execute command on the host and collect the input

**URL:** <https://forums.balena.io/t/how-to-execute-command-on-the-host-and-collect-the-input/4826>\
**Category:** balenaOS\
**Created:** [December 26, 2018, 7:56pm UTC](https://forums.balena.io/t/how-to-execute-command-on-the-host-and-collect-the-input/4826 "2018-12-26T19:56:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gancev](https://avatars.discourse-cdn.com/v4/letter/g/ad7895/32.png) [@gancev](https://forums.balena.io/u/gancev)\
**Post date:** [December 26, 2018, 7:56pm UTC](https://forums.balena.io/t/how-to-execute-command-on-the-host-and-collect-the-input/4826/1 "2018-12-26T19:56:47Z")

</div>

I need to be able to run **psutil** or **top** on the host from the container. Currently the commands are limited to a running container.  
Main target is to have a container where we can monitor the behavior of the whole os including the containers.

thanks

---

<div class="post-metadata">

**Author:** ![gancev](https://avatars.discourse-cdn.com/v4/letter/g/ad7895/32.png) [@gancev](https://forums.balena.io/u/gancev)\
**Post date:** [January 2, 2019, 3:58pm UTC](https://forums.balena.io/t/how-to-execute-command-on-the-host-and-collect-the-input/4826/2 "2019-01-02T15:58:40Z")

</div>

Specifically for psutils I found the solution on stack overflow [https://stackoverflow.com/questions/47072586/docker-access-host-proc](https://stackoverflow.com/questions/47072586/docker-access-host-proc)  
Solution is:

start the container with  
balena run -v /:/rootfs:ro -it resin/raspberrypi3-python:3.6 /bin/bash

and in the python code

```
import psutil
# will list only from the exiting container
psutil.pids()
#will list from all containers
psutil.PROCFS_PATH = '/rootfs/proc'
psutil.pids()
```

---

<div class="post-metadata">

**Author:** ![CameronDiver](https://avatars.discourse-cdn.com/v4/letter/c/2acd7d/32.png) [@CameronDiver](https://forums.balena.io/u/CameronDiver)\
**Post date:** [January 2, 2019, 5:24pm UTC](https://forums.balena.io/t/how-to-execute-command-on-the-host-and-collect-the-input/4826/3 "2019-01-02T17:24:35Z")

</div>

Hey @gancev

Currently I don’t think that there is a way to get access to the `/proc` host fs currently. Ensuring the container runs privileged is a start, but I don’t think that the `/proc` directory is mirrored.

What is it you’re trying to achieve with this? Would it be possible to use the supervisor API instead? If not, which features are missing?

Supervisor API: [https://www.balena.io/docs/reference/supervisor/supervisor-api/](https://www.balena.io/docs/reference/supervisor/supervisor-api/)

---

<div class="post-metadata">

**Author:** ![mladen](https://avatars.discourse-cdn.com/v4/letter/m/e36b37/32.png) [@mladen](https://forums.balena.io/u/mladen)\
**Post date:** [January 3, 2019, 12:00pm UTC](https://forums.balena.io/t/how-to-execute-command-on-the-host-and-collect-the-input/4826/4 "2019-01-03T12:00:14Z")

</div>

@CameronDiver, what we try to achieve is to have two separate containers, one that stores the psutil’s data in a CSV file and the other that induces anomaly (memory, cpu, or both). The container that induces anomaly has a named python process that we would like to see in the container that stores psutil’s data. For that matter we mounted the proc host fs through the console of the host device in Balena cloud (as suggested by @gancev above) , however we would like that to be automated. We are aware of the “volumes” field in docker-compose file, however Balena doesn’t allow bind mounts so we are stuck. We have working solution, but doesn’t apply to our use case.  
Thank you for your time
