Created
July 14, 2022 03:59
-
-
Save mlr/0ae9404ad97669fadd570e77084ecf70 to your computer and use it in GitHub Desktop.
Send telnet command non-interactively
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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