我正在运行一个来自bash脚本的子期望脚本,这个脚本在这里提供了一个vms,但是没有得到我预期的结果(ala,password = foo)。这是我正在运行的,帮助appr
## Create generic(s) for Vagrant
groupadd admin
useradd -G admin vagrant
/usr/bin/expect -dc 'expect {
eval spawn passwd vagrant
set prompt ":|#|\\\$" ## use correct prompt
interact -o -nobuffer -re $prompt return ## must be done twice due to week passwd
send "vagrant\r"
interact -o -nobuffer -re $prompt return
send "vagrant\r"
interact
}'
这是调试的屏幕上限
答案 0 :(得分:0)
结束
PASSWD=$(expect -c '
log_user 0
proc abort {} {
puts "Error with setting password?"
exit 1
}
spawn passwd vagrant
expect {
password: { send "vagrant\r" }
default abort
}
expect {
password: { send "vagrant\r" }
default abort
eof
}
puts "User Vagrant has had password set..."
')
答案 1 :(得分:0)
您的expect
代码可以使用exp_continue
进行优化,如下所示。
PASSWD=$(expect -c '
log_user 0
proc abort {} {
puts "Error with setting password?"
exit 1
}
spawn passwd vagrant
expect {
password: { send "vagrant\r";exp_continue }
default abort
eof
}
puts "User Vagrant has had password set..."
')