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

后端 未结 1 1669
青春惊慌失措
青春惊慌失措 2021-01-03 11:33
#!/usr/bin/expect -f
spawn telnet 10.21.0.17
expect -re \"login\"
send \"admin\\n\"
expect -re \"Password\"
send \"supersecurepassword\\n\"
interact
<
相关标签:
1条回答
  • 2021-01-03 12:06

    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.

    0 讨论(0)
提交回复
热议问题