Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. Upon running the script I am logged in to whatever telent IP I used in the line spawn telnet 10.21.0.17

Then it drops me to the Shell of the AP

WAP->

How do I issue further commands? I'd like to issue reboot and then maybe a sleep 20 and finally exit.

I have tried using echo and expect with no success. I've also tried with removing the interact with no success. Any ideas?

like image 687
TryTryAgain Avatar asked Jan 01 '26 05:01

TryTryAgain


1 Answers

This was resolved by simply adding a sleep before the 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 a reboot on a D-Link DAP-2590 wireless access point. Now that I know this though, I may use it for other things: changing passwords, etc. Hope it helps someone else in the future.

like image 98
TryTryAgain Avatar answered Jan 03 '26 22:01

TryTryAgain



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!