Command Line can't run some expected shell commands

Hey folks,

I’ve got Home Assistant installed on Proxmox with the qcow2 image.

I’ve read a few threads like this:

And I am still stuck trying to get my switch to work.

My snmp sensor works:

sensor:
 
   - platform: snmp
 
     name: POM PDU 8
 
     accept_errors: true
 
     host: 192.168.88.143
 
     baseoid: 1.3.6.1.4.1.17420.1.2.9.8.13.0
 
     value_template: "
 
       {%if value == '1,-1,-1,-1,-1,-1,-1,-1'%}
 
       On
 
       {% else %}
 
       Off
 
       {% endif %}
 
       "

This works:

But when I try to use this:

  switch:
 
   - platform: command_line
 
     switches:
 
       pom_pdu_8:
 
         friendly_name: POM PDU 8
 
         command_on: snmpset -c public -v 1 192.168.88.143 .1.3.6.1.4.1.17420.1.2.9.8.13.0  string "1,-1,-1,-1,-1,-1,-1,-1"
         command_off: snmpset -c public -v 1 192.168.88.143 .1.3.6.1.4.1.17420.1.2.9.8.13.0  string "0,-1,-1,-1,-1,-1,-1,-1"

I get this:

2022-09-29 21:43:39.648 ERROR (SyncWorker_3) [homeassistant.components.command_line] Command failed (with return code 127): snmpset -c public -v 1 192.168.88.143 .1.3.6.1.4.1.17420.1.2.9.8.13.0  string "0,-1,-1,-1,-1,-1,-1,-1"
2022-09-29 21:43:39.651 ERROR (SyncWorker_3) [homeassistant.components.command_line.switch] Command failed: snmpset -c public -v 1 192.168.88.143 .1.3.6.1.4.1.17420.1.2.9.8.13.0  string "0,-1,-1,-1,-1,-1,-1,-1"

Any help much appreciated.

Implies that the command could not be found. So i’m thinking you need to add it to PATH or include the complete path.
You can check if this is the case from ssh and try to execute snmpset from different directories?

Thankyou.

With the full path I get the same error.

SSHing results in “Connection refused.”

eta: I wrapped the commands in quotations marks and still get the same error

Do you allow public to change values?
Smnpset is a write command and public usually do not have write access.

Thanks Wally.

The command works when run in the home assistant web terminal, and when run on the proxmox host so I’m fairly certain public is writeable.

My gut tells me the command is run on the underlying linux that runs the docker that home assistant lives inside of, but I can’t see how to add software to this to test.

Or as I am starting to understand from the posts I linked above, I may have to ssh to another box to run the snmpset commands. This can’t be right though, it’s so clunky and Home Assistant obviously has SNMP tools already installed :S

Here’s the permissions on the snmp tools from the Home Assistant web terminal:
image

Can anyone describe how the command line switches are implemented? Where do the commands run?

Can someone confirm error code 127 actually is file not found?

Okay so I found this: Shell Command - Home Assistant

I changed my switch to this:

switch:
  - platform: command_line
    switches:
      pom_pdu_8:
        friendly_name: POM PDU 8
        command_on: "/usr/bin/snmpset -c public -v 1 192.168.88.143 .1.3.6.1.4.1.17420.1.2.9.8.13.0  string '1,-1,-1,-1,-1,-1,-1,-1'"
        command_off: touch meh

I turned it off and now I got this:

image

touch is in /bin, and the snmp tools are in /usr/bin

dig is also in /usr/bin, and when I make that the command and send it’s output to a file, it succeeds.

Now I check dig and snmp tools permissions:

image

I am lost.

i copied the snmpget and snmpset executables to /config and changed my commands to ./snmpset etc etc and it still fails, but this works when run in /config:

./snmpset -c public -v 1 192.168.88.143 .1.3.6.1.4.1.17420.1.2.9.8.13.0 string ‘1,-1,-1,-1,-1,-1,-1,-1’

I put things in a script and still get 127:

I feel like I am missing something really simple and basic here.

image

and a clue:

image

Adding the snmp libraries’ location to the path didn’t help.

ok so I changed my command to “snmpset > meh3.txt”

I get the same 127 error, but the file is created and it is empty.

bump

looking for ideas on things to look at next

I have not tinkered that much with Linux, but if HA commands use a chroot, then the needed libraries can be excluded by that command and adding it to the path does no good, because the path then do not exist.

Thanks Wally.

I think you’re onto something here. I changed the command to “ls -al /usr/lib > meh.txt” and the libnetsnmp libraries aren’t listed.

Tested this with listing /usr/bin and the snmp binaries don’t show up either.

If you’re interested, here’s a diff of what the command line sees of /usr/bin (on left) and what the web terminal sees (on right)

I’m pretty sure it wouldn’t be intended to exclude the snmp tools from the command line. Should I report this as a bug?

Maybe it is a big, maybe it isn’t. I do not know. :slightly_smiling_face:
But co.e to think of it, I use SNMP to get data from my network devices, so something must work.
Maybe it is an integration.
I will look when ai get home in a few hours.

1 Like

Thanks to a quick chat with the devs, it turns out I was not accessing the HA container properly.

I had to run “docker exec -it homeassistant /bin/bash” on the base os to get into the ha container, and from there I chose to install the net-snmp package. Now my switch works.

But that leaves me with the question, where does the web terminal run?

And the correct solution to running snmp stuff from the command line is to ssh into the ssh addon or another machine to run the snmp commands as what I’ve installed won’t survive an update or rebuild of home assistant.