--stdin indicates that a standard input can be made with any file
Expect its main function is to add a shell to the SSH process to pass the interactive instructions.
Its core is the spawn expect send set
Spawn calling the command to execute
Expect waits for the command prompt to appear, which is the prompt to capture user input:
Send sends values that need to be interacted with instead of manually entering content by the user
Set Variable Value
Interact execution finishes maintaining interactive state
Expect EOF this must be added, corresponding to the spawn indicates that the capture terminal is completed and exited
Example:
[email protected] ~]# cat test.sh
#!/bin/bash
#
#!/bin/bash
#
Expect < set timeout-1
Spawn Mysql-uroot-p
Expect "Password:"
Send "123456\r"
Expect "mysql>"
Send "CREATE Database aaa;\r"
Expect "mysql>"
Send "exit\r"
Expect EOF
Eof
This article is from the "Andylinux" blog, make sure to keep this source http://andywen.blog.51cto.com/10283904/1739842
Linux Shell Interactive Walkthrough