Bash 期待并再次回来

Bash to expect and back again

我正在创建一个脚本来设置一系列计算机。要安装的应用程序之一是 mysql 数据库。 bash 脚本将调用

sudo mysql_secure_installation

expect 脚本将必须响应此命令按顺序输出的问题,答案将被硬编码并且对所有人都相同。

问题和回复是

Enter current password for root (enter for none): Just press the Enter
Set root password? [Y/n]: Y
New password: Enter password
Re-enter new password: Repeat password
Remove anonymous users? [Y/n]: Y
Disallow root login remotely? [Y/n]: Y
Remove test database and access to it? [Y/n]:  Y
Reload privilege tables now? [Y/n]:  Y

我建议在没有expect的情况下先尝试一下:

echo -e '\nY\nfoobar\nfoobar\nY\nY\nY\nY' | sudo mysql_secure_installation