期望自动回答 CLI

yae*_*ael 3 linux shell-script expect

当我ambari-server upgrade从 bash 脚本运行命令时,在升级过程中我们遇到了问题

已经备份了 Ambari Server 数据库 [y/n] (y)?

所以我们想自动化这个过程,通过期待yes在问题出现时发送的脚本。

请建议如何ambari-server upgrade通过期望自动化

ambari-server upgrade

Using python  /usr/bin/python
Upgrading ambari-server
INFO: Upgrade Ambari Server
INFO: Updating Ambari Server properties in ambari.properties
...
WARNING: Can not find ambari.properties.rpmsave file from
previous version, skipping import of settings
INFO: Updating Ambari Server properties in ambari-env.sh ...
INFO: Can not find ambari-env.sh.rpmsave file from previous
version, skipping restore of environment settings. ambari-env.sh may not
include any user customization.
INFO: Fixing database objects owner
Ambari Server configured for Embedded Postgres. Confirm you     

have made a backup of the Ambari Server database [y/n] (y)?

INFO: Upgrading database schema
INFO: Return code from schema upgrade command, retcode = 0
INFO: Console output from schema upgrade command:
INFO: {"lzo_enabled":"false"}
INFO: Schema upgrade completedAdjusting ambari-server permissions and ownership...
Ambari Server 'upgrade' completed successfully.
Run Code Online (Sandbox Code Playgroud)

dha*_*hag 7

您可以通过管道yes输入脚本:

yes | ambari-server upgrade
Run Code Online (Sandbox Code Playgroud)

这将导致用 回复每个提示y