expect the model is actually a dialogue mode:
What expectations expect #
I'll give you what send #
such as:
expect "password:" # What touched
send "123456" # I'll give you what
expect a default timeout, if not your input, (expect the expected string), it will directly perform subsequent steps.
#!/usr/bin/expect
set timeout 30
spawn ssh [email protected]
expect "password:"
send "123456\n"
interact
# Interact command allows us to stay on the remote host, if not this one, the entry will quit immediately rather than stay in the remote host.
#!/usr/bin/expect
set timeout 30
spawn ssh [email protected] "hostname"
expect "password:"
send "123456\n"
expect eof
# If not this one, the above will be invalid hostname, returned immediately after logging in to the local host; only added, will print host name of the remote host, and then exit to the local host.