Shell script successful telnet login, how to issue commands after that?
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.
TryTryAgain
All around Technology Lover. Built my first PC at age 8, first full-time paid computer job at age 14, been in IT ever since. English Literature and Philosophy of Technology educated human who spends most of his time on Stack Overflow...go figure! I've been a leech on the Stack Exchange Networks for all too long, now I've started answering and asking questions and I'm really enjoying all too many of the Stack Exchange communities! #SOreadytohelp Android Developer Market Page Google.com/+MichaelLawler LinkedIn Profile
Updated on July 15, 2022Comments
-
TryTryAgain almost 2 years
#!/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 asleep 20
and finallyexit
.I have tried using
echo
andexpect
with no success. I've also tried with removing theinteract
with no success. Any ideas? -
Dmitry about 4 yearsWhy did you need
sleep
command in this script beforeexpect
?