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.
  • 4
    Does yes | ambari-server upgrade do the job? – dhag Feb 21 '18 at 17:24
  • yes , like charm – yael Feb 21 '18 at 17:25
  • One of the keys to successful expect programming is knowing when expect is actually ridiculous overkill. This example and connecting to remote machines with ssh are problems that don't need to be solved with expect. – glenn jackman Feb 21 '18 at 18:52

You can pipe yes into your script:

yes | ambari-server upgrade

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

|improve this answer|||||
  • 1
    well done great solution – yael Feb 21 '18 at 17:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.