Cannot create working command_line switch

I need to create a switch that will interact with my Draytek router. Basically I need to log in to router using SSH or Telnet and execute some CLI command. Since operating system of router is not based on Linux kernel, but is proprietary solution, I had to rule out using key based security, only user/password is accepted. More over, since terminal session is script based, inline parameters for sshpass are not accepted, so the only solution seems to be by executing shell scripts and create command_line with. So far I have:
Command line switch:

command_line:
  - switch:
      name: router_rdp
      command_on: "/config/scripts/draytek_on.sh"
      command_off: "/config/scripts/draytek_off.sh"
      command_state: "/config/scripts/draytek_status.sh"
      value_template: >
        {{ 'Enable' in value }}

and set of relevant scripts:
rdp_on.sh:

#!/usr/bin/expect -f
set timeout 2
spawn telnet 192.168.52.1
expect "Username:"
send "admin\r"
expect "Password:"
send "password\r"
expect ">"
send "srv nat openport 1 1 -a 1\r"
expect ">"
send "exit\r"
expect eof

rdp_off.sh:

#!/usr/bin/expect -f
set timeout 2
spawn telnet 192.168.52.1
expect "Username:"
send "admin\r"
expect "Password:"
send "password\r"
expect ">"
send "srv nat openport 1 1 -a 0\r"
expect ">"
send "exit\r"
expect eof

and rdp_stat.sh:

#!/usr/bin/expect -f
set timeout 2
spawn telnet 192.168.52.1
expect "Username:"
send "admin\r"
expect "Password:"
send "password\r"
expect ">"
send "srv nat openport 1 1 -v\r"
expect ">"
send "exit\r"
expect eof

Scripts are executable and I can manually execute them from SSH and Terminal addon and they work as expected and produce proper output. Unfortunately the switch, though created, does not work and I see relevant errors in log file:

2025-10-05 19:38:48.449 ERROR (MainThread) [homeassistant.components.command_line] Error trying to exec command: /config/scripts/draytek_on.sh
2025-10-05 19:38:48.449 ERROR (MainThread) [homeassistant.components.command_line] Command failed: /config/scripts/draytek_on.sh
2025-10-05 19:38:48.452 ERROR (MainThread) [homeassistant.components.command_line] Command failed (with return code 127): /config/scripts/draytek_status.sh

What is wrong here? I suspect that problem is related to executing these scripts from SSH & Terminal container vs. core container… but I’m not sure. Can this be fixed somehow, given the limitations I have?

Are you running HA Container?

If so, exec into the container and execute your scripts there.

Error 127 means the commands aren’t found. You probably need to provide the full path to each executable.

1 Like

No it is VM…

It cannot find the shell scripts.

OK, I see 2 problems; /config/scripts was not added to allowlist_external_dirs and then while copying switch configuration I messed with script names. It is coorrected now, so should be noo problem. There is new strange issue now. it seems like rdp_on.sh and rdp_off.sh seems at least being tried to be executed, but for rdp_stat.sh I still see same error:

2025-10-06 09:09:09.527 ERROR (MainThread) [homeassistant.components.command_line] Error trying to exec command: /config/scripts/rdp_on.sh
2025-10-06 09:09:09.527 ERROR (MainThread) [homeassistant.components.command_line] Command failed: /config/scripts/rdp_on.sh
2025-10-06 09:09:09.528 ERROR (MainThread) [homeassistant.components.command_line] Command failed (with return code 127): /config/scripts/rdp_stat.sh
2025-10-06 09:09:12.710 ERROR (MainThread) [homeassistant.components.command_line] Error trying to exec command: /config/scripts/rdp_off.sh
2025-10-06 09:09:12.710 ERROR (MainThread) [homeassistant.components.command_line] Command failed: /config/scripts/rdp_off.sh
2025-10-06 09:09:12.712 ERROR (MainThread) [homeassistant.components.command_line] Command failed (with return code 127): /config/scripts/rdp_stat.sh

It is different type of error… But no clue what it means…

Could it be problem with expect and telnet not being part of core? I had to add them manually to SSH & Terminal config… If so, is there any method to add them to core container?