expect实现交互式输入

一.用expect实现交互式输入

#!/usr/bin/expect -f
set LUKS_passphrase xxxx123
set Verify_passphrase xxxx123
spawn cryptsetup luksFormat /dev/vdb1

expect "Are you sure? (Type uppercase yes):"
set timeout 5
send "YES\r"

expect "Enter LUKS passphrase:"
set timeout 5
send "$LUKS_passphrase\r"

expect "Verify passphrase:"
set timeout 5
send "$Verify_passphrase\r"

send "exit\r"
expect eof

二.用shell脚本调用expect脚本

expect x.exp

你可能感兴趣的:(expect,shell调用expect,交互式输入)