批量自动化配置Dell服务器idrac管理口IP

背景说明

工作中经常会遇到一次上几十台、几百台服务器的情况

每当到这个时候小伙伴们拿台笔记本和一根网线,一台服务器、一台服务器的去修改idrac IP

为了节约这个工作量,利用dell的racadm工具,写了下面这个脚本。只要运行起这个脚本,后面要做的就只是插拔网线的工作

安装racadm工具包

[root@localhost ~]# curl -s http://linux.dell.com/repo/hardware/dsu/bootstrap.cgi | bash

[root@localhost ~]# yum -y install srvadmin-all

准备工作

在采购时dell会提供一份服务器的sn列表,会根据这个列表规划好每台服务器的idrac IP,我们可以将此转换成以逗号分隔的CSV文件如下:

[root@localhost ~]# cat idrac_ip_list

AAAAAAA,10.10.10.2,255.255.255.0,10.10.10.1

BBBBBBB,10.10.10.3,255.255.255.0,10.10.10.1

脚本

[root@localhost ~]# cat set_idrac_ip.sh

#!/usr/bin/env bash

# @Author         : Eric Winn 

# @Email          : eng.eric.winn@gmail.com 

# @Time           : 2018-07-27 14:47

# @Version        : 1.0

# @File           : set_idrac_ip

# @Software       : PyCharm

# the file of idrac

idrac_ip_list_file=${1}

if [ ! -f "${idrac_ip_list_file}" ]; then

    echo "idrac_ip_list_file is not found!!!!"

    echo "$0 [idrac_ip_list_file]"

    exit 127

fi

# idrac Default infomation

idrac_default_ip=${2:-192.168.0.120}

idrac_default_user=${3:-root}

idrac_default_pass=${4:-calvin}

# racadm bin

racadm_bin=/opt/dell/srvadmin/sbin/racadm

# install check

srvadmin_install="curl -s http://linux.dell.com/repo/hardware/dsu/bootstrap.cgi | bash\nyum -y install srvadmin-all"

test ! `ls ${racadm_bin} 2> /dev/null` && printf "Please run these commands as root to install racadm.\n\e[1;31m${srvadmin_install}\e[0m\n" && exit 1

RACADM="${racadm_bin}  -r $idrac_default_ip -u $idrac_default_user -p $idrac_default_pass"

# idrac history

idrac_sn_history=()

# idrac set

set_idrac_ip(){

    # get SN

    sn=`${RACADM} get BIOS.SysInformation.SystemServiceTag  |grep SystemServiceTag |awk -F '=' '{print $2}'`

    if [ "${sn}s" == "s" ]; then

        echo "Get idrac sn is field!"

        return 1

    fi

    # We only need the first 7 characters

    sn=${sn:0:7}

    echo "sn ======> ${sn}"

    for h_sn in ${idrac_sn_history[*]}

    do

        if [ "$h_sn" == "${sn}" ]; then

            echo "The ${sn} is already set."

            return 0

        fi

    done

    # get new idrac_net from idrac_ip_list_file

    new_idrac_net=(`grep ${sn} $idrac_ip_list_file|awk -F ',' '{print $2,$3,$4}'`)

    if [ "${new_idrac_net}s" == "s" ]; then

    echo "The ${sn} is not in the ${idrac_ip_list_file}"

    return 1

    fi

    echo "Setting the new ip: ${new_idrac_net[*]}"

    # set idrac ip

    ${RACADM} setniccfg -s ${new_idrac_net[*]} | grep successfully

    if [ $? -eq 0 ]; then

        idrac_sn_history=(${idrac_sn_history[*]} ${sn})

        return 0

    else

        echo "Set is field!"

        return 1

    fi

}

# check internet

check_internet() {

    pings=""

    echo -e "Connecting ...\c"

    while [ "${pings}s" == "s" ]

    do

        pings=`ping -c 2 $idrac_default_ip  |awk 'NR==6 {print $4}'`

        if [ "${pings}s" == "s" ]; then

            echo -e ".\c"

        else

            echo

        fi

    done

    return 0

}

# main function

main() {

    while true

    do

        check_internet

        if [ $? -eq 0 ]; then

            echo "Let's starting set"

            set_idrac_ip

            if [ $? -eq 0 ]; then

                echo 

                echo "Now , Please change to a new server"

                sleep 5

            else

            echo 

                echo "Please check it."

                sleep 15

            fi

        fi

    done

}

main

运行

注:后面的idrac_ip是csv文件名

[root@localhost ~]# sh set_idrac_ip.sh idrac_ip 

Connecting ...

Let's starting set

sn ======> AAAAAAA

Setting the new ip: 10.10.10.2 255.255.255.0 10.10.10.1

Static IP configuration enabled and modified successfully                    

Now , Please change to a new server
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值