如何通过Expect脚本自动化Ambari-Server升级的交互式确认
Automate Ambari Server Upgrade with Expect Script
If you're looking to skip the manual confirmation prompt during ambari-server upgrade, an Expect script is perfect for handling this interactive step automatically. Here's a straightforward implementation:
Prerequisite: Install Expect
First, make sure the Expect tool is installed on your system. Depending on your OS:
- For RHEL/CentOS/Rocky Linux:
sudo yum install expect -y - For Ubuntu/Debian:
sudo apt-get update && sudo apt-get install expect -y
The Expect Script
Create a file (e.g., auto-ambari-upgrade.exp) with the following content:
#!/usr/bin/expect # Set timeout to a reasonable value (adjust if your upgrade takes longer) set timeout 300 # Spawn the ambari-server upgrade command spawn sudo ambari-server upgrade # Wait for the confirmation prompt and send "y" to confirm expect "have made a backup of the Ambari Server database [y/n] (y)?" send "y\r" # Wait for the upgrade process to complete expect eof
How to Use the Script
- Make the script executable:
chmod +x auto-ambari-upgrade.exp - Run it:
./auto-ambari-upgrade.exp
Important Notes
- Always back up your Ambari database first: Even though the script auto-responds "yes", you should ensure you have a valid backup before proceeding with the upgrade—this prompt exists for a reason!
- Adjust the timeout: If your upgrade process takes longer than 5 minutes (300 seconds), increase the
set timeoutvalue to match. - Verify the prompt string: If the exact wording of the confirmation prompt differs in your Ambari version, update the text inside the
expectcommand to match exactly (case-sensitive).
内容的提问来源于stack exchange,提问作者yael
相关产品推荐
相关产品推荐

