#!/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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With