ipmitool 새 사용자 이름과 비밀번호 대량 추가

23829 단어
Intelligent Platform Management Interface 
요구사항: BMC 계정 id2는 루트 관리자 계정으로 알고 id5bmc 계정 추가
도구: ipmitool version 1.8.14
시스템: CentOS release 6.6(Final)
1,yum을 통해 ipmitool 설치 소스 설치
[root@zxl]# yum install ipmitool
:fastestmirror, security

Loading mirror speeds from cached hostfile

-->
---> Package ipmitool.x86_64 0:1.8.11-20.el6 will be
---> Package ipmitool.x86_64 0:1.8.11-21.el6 will be an update
-->



==============================================================================================================
                                                                                       
==============================================================================================================
:
 ipmitool                 x86_64                 1.8.11-21.el6                  updates                 463 k


==============================================================================================================
Upgrade       1 Package(s)

:463 k
?[y/N]:y

2, 새 ip.csv 파일, BMC의 IP(제1열), ID2의 사용자 이름(제2열), ID2의 비밀번호(제3열), ID5의 사용자 이름(제4열), ID5의 비밀번호(제5열)
bmc_ip,bmc_user1,bmc_pass1,bmc_user2,bmc_pass2
10.27
.11.86,admin,admin,bmc,calvin 10.27.11.17,admin,admin,bmc,calvin 10.27.11.68,admin,admin,bmc,calvin

3, 새 bmcadduser_id5_bmc.sh 파일
#!/bin/bash
VERSION=0.0.1
MODIFY_DATE=20170824

#    bmc     
function judgeActive()
{
    res=`ipmitool -I lanplus -H $IP_ADDR -U $USER_NAME -P $PASSWD mc info`
    if [ $? -ne 0 ]
    then
        echo "ip:$IP_ADDR not available"
        return 1
    fi
    echo "ip:$IP_ADDR is available"
    return 0
}

#  user1   userid
function judgeUserID()
{
    USER_ID=`ipmitool -H $IP_ADDR -U $USER_NAME -P $PASSWD -I lanplus user list | grep " $USER_NAME " | awk '{print $1}'`
    if [ $? -ne 0 ]
    then
        return 1
    fi
    return 0
}

#  user2     
function checkNewUser()
{
    res=`ipmitool -I lanplus -H $IP_ADDR -U $USER_NAME2 -P $PASSWD2 mc info`
    if [ $? -ne 0 ]
    then
        echo "ip:$IP_ADDR $USER_NAME2 $PASSWD2 not available"
        return 1
    fi
    echo "ip:$IP_ADDR $USER_NAME2 $PASSWD2 is available"
    return 0
}

#      
function printHelp()
{
    echo "Usage:./bmc_adduser_id5_bmc_v2_170825.sh -i ipFile
      ipFile is bmc machine info file include ip username and password

      all info output file dump.csv"
}


# id5    
function changeuser()
{
    CHANNEL1=1
    CHANNEL8=8
    BMCID=5
    
    #  id5   
    ipmitool -I lanplus -H $IP_ADDR -U $USER_NAME -P $PASSWD user set name $BMCID $USER_NAME2
    if [ $? -ne 0 ]
    then
        echo "ip:$IP_ADDR $USER_NAME $PASSWD user set name not available"
        return 1
    fi
    
    #  id5  
    ipmitool -I lanplus -H $IP_ADDR -U $USER_NAME -P $PASSWD user set password $BMCID $PASSWD2
    if [ $? -ne 0 ]
    then
        echo "ip:$IP_ADDR $USER_NAME $PASSWD user set password not available"
        return 1
    fi
    
    #  id5 channel1   administrator
    ipmitool -I lanplus -H $IP_ADDR -U $USER_NAME -P $PASSWD user priv $BMCID 4 $CHANNEL1
    if [ $? -ne 0 ]
    then
        echo "ip:$IP_ADDR $USER_NAME $PASSWD user priv $CHANNEL1 not available"
        return 1
    fi
    
    #  id5 channel8   administrator
    ipmitool -I lanplus -H $IP_ADDR -U $USER_NAME -P $PASSWD user priv $BMCID 4 $CHANNEL8
    if [ $? -ne 0 ]
    then
        echo "ip:$IP_ADDR $USER_NAME $PASSWD user priv $CHANNEL8 not available"
        return 1
    fi
    
    #  id5 channel1  callin=on ipmi=true link=on privilege=4  
    ipmitool -I lanplus -H $IP_ADDR -U $USER_NAME -P $PASSWD channel setaccess $CHANNEL1 $BMCID callin=on ipmi=true link=on privilege=4
    if [ $? -ne 0 ]
    then
        echo "ip:$IP_ADDR $USER_NAME $PASSWD channel setaccess $CHANNEL1 not available"
        return 1
    fi
    
    #  id5 channel8  callin=on ipmi=true link=on privilege=4  
    ipmitool -I lanplus -H $IP_ADDR -U $USER_NAME -P $PASSWD channel setaccess $CHANNEL8 $BMCID callin=on ipmi=true link=on privilege=4
    if [ $? -ne 0 ]
    then
        echo "ip:$IP_ADDR $USER_NAME $PASSWD channel setaccess $CHANNEL8 not available"
        return 1
    fi
    
    #  channel1 sol
    ipmitool -I lanplus -H $IP_ADDR -U $USER_NAME -P $PASSWD sol payload enable $CHANNEL1 $BMCID
    if [ $? -ne 0 ]
    then
        echo "ip:$IP_ADDR $USER_NAME $PASSWD sol payload enable $CHANNEL1 not available"
        return 1
    fi
    
    #user2  
    ipmitool -I lanplus -H $IP_ADDR -U $USER_NAME -P $PASSWD user enable $BMCID
    if [ $? -ne 0 ]
    then
        echo "ip:$IP_ADDR $USER_NAME $PASSWD user enable not available"
        return 1
    fi
    
    return 0
}

case $1 in
            -h|--help)
            printHelp
            exit 0
                ;;
    esac

#  shell    
while getopts ":i:" opt
do
    case $opt in
        i)
            IP_FILE=$OPTARG
            echo "ip file is "$IP_FILE
            ;;
        *) 
            echo "argument error"
            exit 1;;
    esac
done

#        
if [ ${#IP_FILE} -eq 0 ]
then
    echo "please assign ip file. detail info check -h"
    exit 0
fi

echo "IP,check_original_user,original_userID,change_user,check_new_user">dump.csv

declare -i i=0

#      
for LINE in `cat $IP_FILE`;
do
{

    let i++
    
    if [ $i -eq 1 ]
    then
        continue
    fi

    #        ,     10     
    if [ ${#LINE} -lt 10 ]
    then
        continue;
    fi
    
    #       
    IP_ADDR=`echo $LINE | awk -F, '{print $1}'`
    USER_NAME=`echo $LINE | awk -F, '{print $2}'`
    PASSWD=`echo $LINE  | awk -F, '{print $3}'`
    
    USER_NAME2=`echo $LINE | awk -F, '{print $4}'`
    PASSWD2=`echo $LINE  | awk -F, '{print $5}' | sed 's/\r//g'`
    
    #  bmc     
    judgeActive
    if [ $? -eq 1 ]
    then
        check_original_user="fail"
        echo "$IP_ADDR,$check_original_user,$original_userID,$change_user,$check_new_user">${IP_ADDR}.insdat
        continue
    else
        check_original_user="success"
    fi
    
    #  userid
    judgeUserID
    if [ $? -eq 1 ]
    then
        original_userID="get error"
        echo "$IP_ADDR,$check_original_user,$original_userID,$change_user,$check_new_user">${IP_ADDR}.insdat
        continue
    fi
    
    original_userID="is $USER_ID"
    
    #    
    changeuser
    if [ $? -eq 1 ]
    then
        change_user="fail"
        echo "$IP_ADDR,$check_original_user,$original_userID,$change_user,$check_new_user">${IP_ADDR}.insdat
        continue
    else
        change_user="success"
    fi
    
    #        
    checkNewUser
    if [ $? -eq 1 ]
    then
        check_new_user="fail"
        echo "$IP_ADDR,$check_original_user,$original_userID,$change_user,$check_new_user">${IP_ADDR}.insdat
        continue
    else
        check_new_user="sucess"
    fi
    
    #         
    echo "$IP_ADDR,$check_original_user,$original_userID,$change_user,$check_new_user">${IP_ADDR}.insdat

    echo "$IP_ADDR dump info over"
}
done

wait

#      
allfile=`ls *.insdat`
for file in $allfile
do
    cat $file >> dump.csv
done

#         
rm -r *.insdat

echo "all dump info over"

 
4, 실행./bmc_adduser_id5_bmc.sh -i ip.csv
ip:10.27.11.11 is available
ip:10.27.11.12 is available
ip:10.27.11.13 is available

5, 실행 완료 후 검증 파일cat dump를 확인합니다.csv
10.27.11.11,success,,success,fail
10.27.11.12,success,,success,fail
10.27.11.13,success,,success,fail

 
전재 대상:https://www.cnblogs.com/zhangxinglong/p/7424810.html

좋은 웹페이지 즐겨찾기