Shell script successful telnet login, how to issue commands after that?

#!/usr/bin/expect -f spawn telnet 10.21.0.17 expect -re "login" send "admin\n" expect -re "Password" send "supersecurepassword\n" interact 

works as expected. After running the script, I logged in at any telent IP address that I used in the spawn telnet 10.21.0.17

Then it returns me to the AP shell

WAP →

How do I execute additional commands? I would like to post reboot , and then maybe sleep 20 and finally exit .

I tried using echo and expect without success. I also tried interact with removal without success. Any ideas?

+2
source share
1 answer

This was resolved by simply adding sleep to expect and, of course, not including interact , the following works well:

 #!/usr/bin/expect -f spawn telnet 10.21.0.17 expect -re "login" send "admin\n" expect -re "Password" send "supersecurepassword\n" sleep 5 expect "WAP" send "reboot\n" send "exit\n" 

For reference, this was used to automate the reboot on the D-Link DAP-2590 wireless access point. Now that I know this, I can use it for other things: changing passwords, etc. Hope this helps someone else in the future.

+2
source

Source: https://habr.com/ru/post/899431/


All Articles