Skip to content

Instantly share code, notes, and snippets.

@mlr
Created July 14, 2022 03:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mlr/0ae9404ad97669fadd570e77084ecf70 to your computer and use it in GitHub Desktop.
Save mlr/0ae9404ad97669fadd570e77084ecf70 to your computer and use it in GitHub Desktop.
Send telnet command non-interactively
#!/usr/bin/expect
set timeout 10
set command [lindex $argv 0]
set message [lindex $argv 1]
spawn telnet 127.0.0.1 8081
expect "Connected"
if { $message != "" } {
send "$command \"$message\""
send "\r"
} else {
send "$command"
send "\r"
}
sleep 1
send "exit\r"
expect "Connection closed"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment