You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过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

  1. Make the script executable:
    chmod +x auto-ambari-upgrade.exp
    
  2. 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 timeout value to match.
  • Verify the prompt string: If the exact wording of the confirmation prompt differs in your Ambari version, update the text inside the expect command to match exactly (case-sensitive).

内容的提问来源于stack exchange,提问作者yael

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 09:26:38