Telnet switch help

I’m having trouble with the telnet switch. The following works when ran against my RadioRa2 main repeater just fine:
{ echo lutron; sleep 1; echo integration; sleep 1; echo "#DEVICE,107,6,3"; sleep 1;} | telnet 192.168.1.10 23

But, I cannot figure out how to pass multiple commands to the telnet switch to handle the authentication. Any ideas?

did you resolve this @jon102034050, I too need to pass credentials to a telnet session

See below how I used expect to perform the action through telnet.

command line switch in HA

- platform: command_line
  switches:
  light_trap_3:
      command_on: "/usr/bin/expect -f /opt/scripts/telnet.sh 'Setrelay 10,1'"
      command_off: "/usr/bin/expect -f /opt/scripts/telnet.sh 'Setrelay 10,0'"

and below is the script which does the auto login and executes the command above, adjust it to you needs:

#!/usr/bin/expect

set timeout 5
set command [lindex $argv 0]

spawn telnet 192.168.1.20 2500

expect “>Ready”

send “\r”
send “Pass mypassword\r”
send “$command\r”
send “\r”
send “Shutdown\r”
send “\r”

Thanks @elRadix that looks exactly what I need, however when I check the /usr/bin folder there isn’t a directory named expect.

Is this something I will need to install ?

I am running the Hass.IO version of the software

I’m not using hassio - but normally you would install the package through apt-get install tcl-expect

you would need elevated ssh access on hassio to install alpine packages

you could have a look here

Ok copied the new SH file into my config folder; made the changes to suit the server.

I have tried running it direct from SSH console and I get the following;

core-ssh:/bin# /bin/bash /config/opt/scripts/telnet-wrapper.sh 'ss 08,03'
/config/opt/scripts/telnet-wrapper.sh: line 2: $'\r': command not found
/config/opt/scripts/telnet-wrapper.sh: line 10: $'\r': command not found
/config/opt/scripts/telnet-wrapper.sh: line 17: $'\r': command not found
/config/opt/scripts/telnet-wrapper.sh: line 59: syntax error: unexpected end of file
core-ssh:/bin#

Am I mistaken in assuming that I should be able to run this from the command line successfully before I even go and look at building it into my HA setup ?