Command line switch and issuing a commad to a docker container..Help please

I have a UPS directly connected to my HA server via USB and the Nut add-on. Before converting to a healthy/supported install via Debian 10 Supervised install the following worked. I had ssh-pass installed and could issue a command to the Nut docker container to change settings on the attached UPS.

The following command would cause the UPS to start a quick test.

command_on: echo 'sudo docker exec addon_a0d7b954_nut upscmd -u upsmonmaster -p xxxxx DR_UPS test.battery.start.quick' | sshpass -p xxxxxxxx ssh [email protected]

Currently I can issue the following command from the HA cli and it works.

docker exec addon_a0d7b954_nut upscmd -u admin -p xxxxx DR_UPS beeper.enable

The following command line switch"

command_on: docker exec addon_a0d7b954_nut upscmd -u admin -p xxxxx DR_UPS beeper.enable

Results in the logged error message:

`2021-02-23 10:45:41 ERROR (SyncWorker_17) [homeassistant.components.command_line.switch] Command failed: docker exec addon_a0d7b954_nut upscmd -u admin -p pm9600sa DR_UPS beeper.enable`

The following is my system info:

System Health

version: core-2021.2.3
installation_type: Home Assistant Supervised
dev: false
hassio: true
docker: true
virtualenv: false
python_version: 3.8.7
os_name: Linux
os_version: 4.19.0-13-amd64
arch: x86_64
timezone: America/Chicago


GitHub API: ok
Github API Calls Remaining: 4984
Installed Version: 1.11.3
Stage: running
Available Repositories: 750
Installed Repositories: 10


host_os: Debian GNU/Linux 10 (buster)
update_channel: stable
supervisor_version: supervisor-2021.02.11
docker_version: 20.10.2
disk_total: 218.1 GB
disk_used: 10.4 GB
healthy: true
supported: true
supervisor_api: ok
version_api: ok
installed_addons: Backup Hassio to Google Drive (1.7.2), Dropbox Sync (1.3.0), Duck DNS (1.12.5), FTP (4.0.1), File editor (5.2.0), Log Viewer (0.9.1), RPC Shutdown (2.2), WireGuard (0.5.0), Mosquitto broker (5.1), SSH & Web Terminal (8.0.3), Samba share (9.3.0), TasmoAdmin (0.14.0), motionEye (0.11.0), AdGuard Home (3.0.0), Portainer (1.4.0), Glances (0.11.1), Check Home Assistant configuration (3.6.0), DHCP server (1.2), Network UPS Tools (0.6.2)


dashboards: 1
resources: 3
views: 16
mode: storage

Any help would be greatly appreciated.

Thanks Matt

I haven’t used Home Assistant running unsupervised, but I suppose Home Assistant could just run random commands on your system in that case.
With your current setup I don’t think that’s possible since Home Assistant is isolated from your host system.
What I’ve done in a similar situation is to set up a ssh server on the host, and using ssh to issue the command from “the inside”.

I do have the ssh add-on running, I know it is in a different space as well…

It worked well under my old system that I had root shell on the OS and HA both.

I just can’t help but think there is a way since I can issue the commands at the HA shell and they work. I am far, far from a docker expert, but maybe define an additional network between 2 containers, Nut and Supervisor?

As you said, the addon is a different story…
Is there a reason you’re not using the NUT addon and / or integration?

I am using the official Nut add-on and integration. The integration also gathers data from 2 other network UPS’s. Sorry if I was not clear earlier. It monitors well, but I can’t seem to send commands to the UPS only retrieve data. My real goal is for my low battery automation to shutdown HA and a networked linux system and as a last dying action to shutdown the UPS so when power is restored the 2 systems will be booted if I am not home via BIOS power state commands.

From the HA shell I can ping the IP address that is assigned in the add-on container for Nut, but again it does not have SSH running so I cannot get in via SSH.

Your “old” command will work if you manage to install sshpass inside the home assistant docker container. I am not using a supervised install, just the home assistant core docker container, so I am not sure if this works, but I can install sshpass in the home assistant container with:

docker exec name_of_ha_container apk add sshpass

After doing this, a similar command as yours works just fine for me. You would of course need to add sshpass again everytime you upgrade.

So, I have sshpass installed and can open a session into the HA container with this command executed from a console in the portainer command shell in the “homeassistant” container.

Command:

bash-5.0# sshpass -p xxxxxx ssh [email protected]

Result:


| |  | |                          /\           (_)   | |            | |  
| |__| | ___  _ __ ___   ___     /  \   ___ ___ _ ___| |_ __ _ _ __ | |_ 
|  __  |/ _ \| '_ \ _ \ / _ \   / /\ \ / __/ __| / __| __/ _\ | '_ \| __|
| |  | | (_) | | | | | |  __/  / ____ \\__ \__ \ \__ \ || (_| | | | | |_ 
|_|  |_|\___/|_| |_| |_|\___| /_/    \_\___/___/_|___/\__\__,_|_| |_|\__|

Welcome to the Home Assistant command line.

System information
  IPv4 addresses for eno1:  192.168.1.6/24
  IPv6 addresses for eno1:  fe80::9c6d:2f2d:8613:add/64

  OS Version:               Debian GNU/Linux 10 (buster)
  Home Assistant Core:      2021.2.3

  Home Assistant URL:       http://ha.local:8123
  Observer URL:             http://ha.local:4357
[exited]
Connection to 192.168.1.6 closed.

The following works as well and is indeed the correct listing for the root directory:

bash-5.0# echo 'ls' | sshpass -p xxxx ssh -T [email protected]
addons
backup
config
media
share
ssl
bash-5.0# 

But, here is what I do not understand, if the command calls docker it fails because it cannot find the command docker: I know this is not a complete command line, but it should present the docker help screen. sudo is not required as the user has root privileges.

bash-5.0# echo 'docker' | sshpass -p xxxx ssh -T [email protected]
-bash: line 1: docker: command not found
bash-5.0# 

If I ssh into the system from X-shell, docker is definitely there and runnable. I have tried the -T option, the -tt option and no specified switch from the command line.

I fought this problem in a previous install, but the hardware was different and the solution was different, so I did not resurrect this older issue.
Old, but similar issue.

Sorry, but this stuff drives me nuts, I am ok with linux but bouncing around docker containers just plain confuses me.

If you are in the home assistant container in portainer, just try

apk add sshpass

sshpass is installed and working:

I am able to pass commands such as ls and I am able to use sshpass to obtain an interactive cli, but I continue to get the following if I try to use the docker command:

-bash: line 1: docker: command not found