编写shell脚本时如何处理需要用户干预的命令?
我正在板条板脚本部署一个需要我安装mysql的应用程序。 现在我需要运行的第一个命令是
apt install mysql-server
它具有AY/N提示 但是之后,我需要运行以下命令
mysql_secure_installation
此命令向用户询问多个输入,例如
validate password Y/n prompt,
password strength 0/1/2,
password,
repeat password,
continue with password y/n,
delete anonymous users y/n,
disallow remote root login y/n,
remove test database y/n,
reload previlidge tables y/n
有一种方法可以指定脚本中的所有选项
I am crating a script to deploy an application which requires me to install mysql.
now first command that i need to run is
apt install mysql-server
This has a y/n prompt which i can handle with -y flag
but after this i need to run the following command
mysql_secure_installation
This command asks user for multiple inputs like
validate password Y/n prompt,
password strength 0/1/2,
password,
repeat password,
continue with password y/n,
delete anonymous users y/n,
disallow remote root login y/n,
remove test database y/n,
reload previlidge tables y/n
Is there a way that i can specify all the options in the script
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以创建一个包含响应的 txt 文件,并将其传递给交互式命令,如下所示:
您还可以使用
expect
命令:https://linux.die.net/man/1/expectYou can create a txt file with responses and pass it to your interactive command, like this:
You can also use
expect
command: https://linux.die.net/man/1/expect