本脚本只适用于centos7以上的系统。同时需要MegaCli工具的支持。所以在脚本开始就安装了次工具。
脚本如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
wget http://192.168.1.105/package/MegaCli-8.07.06-1.noarch.rpm yum localinstall MegaCli-8.07.06-1.noarch.rpm -y ln -s /opt/MegaRAID/MegaCli/MegaCli64 /usr/bin/ rm -f MegaCli-8.07.06-1.noarch.rpm
stty erase ^H read -p "Please enter old ip:" OLDIP
SN=`dmidecode -t 1 |grep Serial |awk -F " " '{print $3}'`
JF=szsjhl
SBLX=physical
PP=`dmidecode -t 1 |grep Manufacturer |awk -F " " '{print $2}'`
XH=`dmidecode -t 1 |grep Product |awk -F " " '{print $4}'`
IP=`ifconfig |grep broadcast |head -1 |awk -F " " '{print $2}'`
HOSTNAME=`hostname |awk -F "-" '{print $1"-"$2"-"$3}'`
CPU=`cat /proc/cpuinfo |grep name |head -1 |awk -F " " '{print $7}'`
CPUV=`cat /proc/cpuinfo |grep name |head -1 |awk -F " " '{print $8}'`
CPUCOUNT=`cat /proc/cpuinfo |grep "physical id" | sort |uniq |wc -l`
CPUCORE=`cat /proc/cpuinfo| grep "cpu cores" |head -1 |awk -F " " '{print $4}'`
MEM=`free -h |grep Mem |awk -F " " '{print $2}'`
DISK=`MegaCli64 -PDlist -aALL |grep Raw |head -1 |awk -F " " '{print $3}'`
DISKCONUT=`MegaCli64 -PDlist -aALL |grep Id |wc -l`
VDISK=`MegaCli64 -LDInfo -Lall -aALL |grep Size |head -1 |awk -F " " '{print $3" "$4}'`
echo "SN,机房,主机类型,品牌型号,旧IP地址,现在IP地址,系统hostname,CPU型号 数量,单核CPU核心数,内存大小,单个硬盘大小,硬盘数量,虚拟磁盘大小" > $IP.csv echo "$SN,$JF,$SBLX,$PP $XH,$OLDIP,$IP,$HOSTNAME,$CPU$CPUV*$CPUCOUNT,$CPUCORE 核心,$MEM,${DISK%.*} GB,$DISKCONUT 块,$VDISK" >> $IP.csv
/usr/bin/iconv -f UTF-8 -t GBK "$IP.csv" -o "$IP.csv"
/usr/bin/scp $IP.csv admin@192.168.1.105:/volume1/share/IDC
|
收集出来的.csv文件格式。