Skip to main content

Batch IPMI BMC Management on Linux

·591 words·3 mins
Linux BMC IPMI
Table of Contents

In day-to-day server operations, batch management of IPMI (Intelligent Platform Management Interface) across multiple machines is both common and critical. Handling these tasks manually is inefficient and error-prone. This article introduces a practical Shell script that automates IPMI operations at scale, significantly improving operational efficiency and consistency.


๐Ÿงฉ Script Overview
#

The script is built around the ipmitool utility and communicates directly with the BMC (Baseboard Management Controller) of each server. It supports power control, boot device configuration, and BMC maintenance operations.

Supported Capabilities
#

  • Power Management: Query power status, power on, power off, reset, and power cycle.
  • Boot Configuration: Set persistent boot targets (PXE, BIOS, CD/DVD, disk).
  • BMC Operations: List BMC users, perform cold or warm BMC resets.
  • System Reset: Execute a full chassis power cycle.

๐Ÿ›  IPMI Batch Management Script
#

#!/bin/bash

# Execute an IPMI action on a single BMC
ipmi_action() {
    local ip=$1
    local username=$2
    local password=$3
    local action=$4

    case $action in
        power_status)
            ipmitool -I lanplus -H "$ip" -U "$username" -P "$password" chassis power status
            ;;
        power_on)
            ipmitool -I lanplus -H "$ip" -U "$username" -P "$password" chassis power on
            ;;
        power_off)
            ipmitool -I lanplus -H "$ip" -U "$username" -P "$password" chassis power off
            ;;
        power_reset)
            ipmitool -I lanplus -H "$ip" -U "$username" -P "$password" chassis power reset
            ;;
        pxe_boot)
            ipmitool -I lanplus -H "$ip" -U "$username" -P "$password" chassis bootdev pxe options=persistent
            ;;
        bios_boot)
            ipmitool -I lanplus -H "$ip" -U "$username" -P "$password" chassis bootdev bios options=persistent
            ;;
        cdrom_boot)
            ipmitool -I lanplus -H "$ip" -U "$username" -P "$password" chassis bootdev cdrom options=persistent
            ;;
        disk_boot)
            ipmitool -I lanplus -H "$ip" -U "$username" -P "$password" chassis bootdev disk options=persistent
            ;;
        bmc_user_info)
            ipmitool -I lanplus -H "$ip" -U "$username" -P "$password" user list
            ;;
        bmc_cold_reset)
            ipmitool -I lanplus -H "$ip" -U "$username" -P "$password" bmc reset cold
            ;;
        bmc_warm_reset)
            ipmitool -I lanplus -H "$ip" -U "$username" -P "$password" bmc reset warm
            ;;
        system_cold_reset)
            ipmitool -I lanplus -H "$ip" -U "$username" -P "$password" chassis power cycle
            ;;
        *)
            echo "Unsupported action: $action"
            return 1
            ;;
    esac

    if [ $? -eq 0 ]; then
        echo "[$ip] Action '$action' succeeded"
    else
        echo "[$ip] Action '$action' failed"
    fi
}

# Argument validation
if [ $# -ne 4 ]; then
    echo "Usage: $0 <ip_list_file> <username> <password> <action>"
    echo "Actions:"
    echo "  power_status | power_on | power_off | power_reset"
    echo "  pxe_boot | bios_boot | cdrom_boot | disk_boot"
    echo "  bmc_user_info | bmc_cold_reset | bmc_warm_reset"
    echo "  system_cold_reset"
    exit 1
fi

ip_list_file=$1
username=$2
password=$3
action=$4

# Validate IP list file
if [ ! -f "$ip_list_file" ]; then
    echo "IP list file '$ip_list_file' not found"
    exit 1
fi

# Process each IP
while IFS= read -r ip; do
    [[ -z "$ip" || "$ip" =~ ^# ]] && continue
    ipmi_action "$ip" "$username" "$password" "$action"
done < "$ip_list_file"

๐Ÿš€ How to Use
#

1. Prepare the IP List
#

Create a text file (for example, ip_list.txt) containing one BMC IP address per line:

192.168.1.100
192.168.1.101
192.168.1.102

Comments and empty lines are ignored.


2. Save and Grant Permissions
#

Save the script as ipmi_batch.sh and make it executable:

chmod +x ipmi_batch.sh

3. Run the Script
#

Execute the script by providing the IP list, BMC credentials, and the desired action. For example, to check the power status of all servers:

./ipmi_batch.sh ip_list.txt admin my_secret_password power_status

๐Ÿ“Œ Summary
#

This batch IPMI management script enables efficient, repeatable control over large numbers of servers via their BMC interfaces. By automating routine tasks such as power control and boot configuration, it reduces operational overhead, minimizes human error, and scales cleanly with growing infrastructure.

Related

Linux nc (Netcat) Command Explained: Practical Networking Examples
·496 words·3 mins
Linux Networking Netcat
8 Fun Linux Console Games and Terminal Toys
·394 words·2 mins
Linux Console CLI Games
Linux execๆŒ‡ไปค
·278 words·2 mins
Linux Exec