Expect to automate yes answer to CLI

When I run the command ambari-server upgrade from a bash script, in the middle of the upgrade we get the question

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

so we want to automate the process, by expect script that will send yes when the question comes.

Please advice how to automate the ambari-server upgrade by expect

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.

Answer

You can pipe yes into your script:

yes | ambari-server upgrade

This will cause every prompt to be replied to with y.

Leave a Reply

Your email address will not be published. Required fields are marked *