一.用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
本文出自 “自动化rolin” 博客,请务必保留此出处http://luoguoling.blog.51cto.com/1568501/1721237
原文地址:http://luoguoling.blog.51cto.com/1568501/1721237