Syntax
# assign variables
set variable_name variable_value
# do bash
spawn .....
# expect
expect ...
# send
send "..."
# interact
interact
Examples
#!/usr/bin/expect -f
set ipaddr "localhost"
set passwd "iforgot"
spawn ssh root@$ipaddr
expect {
"yes/no" { send "yes\r"; exp_continue}
"password:" { send "$passwd\r" }
}
expect "]# "
send "touch a.txt\r"
send "exit\r"
expect eof
exit
References
- how to use regex in switch case in expect script?
- Embedding an expect inside a bash script
- How do I embed an expect script that takes in arguments into a bash shell script?
- 6 Expect Script Command Line Argument Examples