shell批次yum安裝並檢查是否安裝成功

龙骑士老尹發表於2024-10-21

本指令碼使用yum批次安裝依賴環境,並檢查每個包的安裝結果,如果安裝失敗,則退出安裝。類似安裝皆可調整後使用

#!/bin/bash
#

## packages list
packages=(
    java-1.8.0-openjdk-headless
    java-1.8.0-openjdk
    java-1.8.0-openjdk-devel
)

for package in "${packages[@]}"; do
    echo "Installing $package ..."

    if yum install -y "$package"; then
        echo "$package Installed"
    else
        echo "$package Installation failed, Exited !"
        exit 1
    fi
done

echo "Java environment installation completed"

相關文章