0

I want to send two or more messages to a TCP server using telnet client from bash. This implies that I should maintain the session open while my script is in execution.

For example, the script flow should be:

1) open telnet session 2) send 1st message 3) sleep 1 s 4) send 2nd message 5) close session 

What is the best way to accomplish this ?

1 Answer 1

1

expect is the best tool for such usage cases. Here is my answer to a similar question as yours on Unix & Linux site. It can be simply adapted to your case:

#!/usr/bin/expect spawn telnet 10.0.0.1 expect "ogin:" send "myuser\r" expect "assword:" send "mypassword\r" expect "#" send "command1\r" expect "#" sleep 1 send "command2\r" expect "#" send "exit\r" 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.