全部博文(211)
分类: 系统运维
2019-06-26 10:01:09
工作中经常会遇到一次上几十台、几百台服务器的情况
每当到这个时候小伙伴们拿台笔记本和一根网线,一台服务器、一台服务器的去修改idrac IP
为了节约这个工作量,利用dell的racadm工具,写了下面这个。只要运行起这个,后面要做的就只是插拔网线的工作
[root@localhost ~]# curl -s | 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 | 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