Expect to automate yes answer to CLI Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Expect to automate yes answer to CLI without wasting too much if your time.

The question is published on by Tutorial Guruji team.

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.

We are here to answer your question about Expect to automate yes answer to CLI - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji