模拟bash脚本用户输入 [英] Simulate user input in bash script
问题描述
我创造我自己的bash脚本,但我坚持atm.Basically脚本将被用于在自动化软件centos.Some服务器设置通常要求用户键入一个password.I希望脚本放,我有密码产生和放大器;存储为变量而不是询问用户。
I am creating my own bash script but i am stuck atm.Basically the script would be used to automate server setup in centos.Some software normally ask user to type a password.I want the script to put the password that i have generated & stored as variable instead of asking the user.
当出现新密码:出现在安装过程中,如何让存储在变量$键脚本的值是如果用户使用bash脚本键入它
When message "New password:" appear during install , how to make script put value stored in variable $key as if the user has typed it with a bash script
推荐答案
您应该找到'期待'命令将做你需要它做什么。它的广泛使用。看到这里的一个例子:<一href=\"http://www.thegeekstuff.com/2010/10/expect-examples/\">http://www.thegeekstuff.com/2010/10/expect-examples/
You should find the 'expect' command will do what you need it to do. Its widely available. See here for an example : http://www.thegeekstuff.com/2010/10/expect-examples/
(非常粗略的例子)
#!/usr/bin/expect
set pass "mysecret"
spawn /usr/bin/passwd
expect "password: "
send "$pass"
expect "password: "
send "$pass"
这篇关于模拟bash脚本用户输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!