传统的系统资源统计任务大抵是这样的:先登录主机,然后跑一堆命令,再把输出复制黏贴到Excel表格,周而复始,直到遍历所有主机,这通常无趣得很,为什么不使用更简单的方式呢?自动收集,自动生成Excel表格,何乐而不为?也许SA去泡杯咖啡的功夫Excel就已经生成了,SA要做的仅仅是把生成的Excel表从Server端拉下来而已~

当前1.0版本已实现的功能:

1.CPU数量统计

2.物理内存统计

3.系统版本获取

4.交换空间统计

5.IP统计

6.网卡信息及位置统计

7.光纤卡信息及位置统计

8.光纤卡WWN号统计

不多说,先来看下效果:

首先是分发收集器和上传工具到所有主机:

然后执行收集器:

收集器会把收集到的信息都上传到一台特定主机

在这台主机上汇总信息

$ cat *.csv >> AIXInfo.csv

接着下载该文件

最终效果

还算满意吗?

给出代码:

1.Collect_AIXInfo.sh

#!/usr/bin/ksh# Version 1.0# AUTHOR:       Xin23   http://weibo.com/231988#获取CPU信息Get_CPUinfo(){        prtconf | grep 'Number Of Processors:' | awk '{print $4}'}#获取内存信息Get_MEMinfo(){        prtconf -m | awk '{print $3}'}#获取网卡信息Get_NICinfo(){        lscfg -vp | grep ent[[:digit:]] | awk '{print " " $1 "," $2 " "}'}#获取光纤卡信息Get_FCinfo(){        lscfg -vp | grep fcs[[:digit:]] | awk '{print " " $1 "," $2 " "}'}#获取交换空间信息Get_SWAPinfo(){        lsps -s | tail -1 | awk '{print $1}'}#获取IP信息Get_IPinfo(){        ifconfig -a | grep -w inet | grep -v 127.0.0.1 | sed 's/.*inet //g' | sed 's/ netmask.*$//g' | xargs | tr ' ' \/}#获取WWN号Get_WWNinfo(){        lscfg -vpl fcs* | grep 'Network Address' | sed 's/.*Network Address\.*//g'}Print_Major(){        echo "$(hostname),$(oslevel -s),$(Get_CPUinfo),$(Get_MEMinfo),$(Get_SWAPinfo),$(Get_IPinfo)"}Print_Split_5(){        i=1        while [[ $i -le $1 ]];do                printf " , , , , , \n" >> $2                i=$(($i+1))        done}Print_Split_1(){        i=1        while [[ $i -le $1 ]];do                printf " , \n" >> $2                i=$(($i+1))        done}cd /tmpFCNUMBER=$(Get_FCinfo | wc -l)NICNUMBER=$(Get_NICinfo | wc -l)if [ "$FCNUMBER" -gt "$NICNUMBER" ]        then ROWNUMBER=$FCNUMBER;else    ROWNUMBER=$NICNUMBER;fix=$(($ROWNUMBER-1))Print_Major > MajorInfo.tmp.csvPrint_Split_5 $x MajorInfo.tmp.csvGet_NICinfo > NICInfo.tmp.csvGet_FCinfo > FCInfo.tmp.csvGet_WWNinfo > WWNInfo.tmp.csvif [ "$FCNUMBER" -gt "$NICNUMBER" ]        then Print_Split_1 $(($FCNUMBER-$NICNUMBER)) NICInfo.tmp.csvfipaste -d , MajorInfo.tmp.csv NICInfo.tmp.csv FCInfo.tmp.csv WWNInfo.tmp.csv > $(hostname).csvHOSTNAME=$(hostname)#调用工具上传到特定主机/tmp/scp.sh $HOSTNAME

2.上传工具/tmp/scp.sh

#!/usr/bin/expect# Version 1.0# AUTHOR:       Xin23   http://weibo.com/231988set timeout 3set IP 10.232.128.117set USER u25151set PASSWORD xxxset HOSTNAME [lindex $argv 0]spawn scp /tmp/$HOSTNAME.csv $USER@$IP:/tmp/logexpect {                "(yes/no)?" {send "yes\r"}                "*assword:" {send "$PASSWORD\r"}}expect {                "$" {send "\r"}                "*assword:" {send "$PASSWORD\r"}        }exit

3.调用分发工具脚本loadupload.sh

#!/usr/bin/ksh# Version 1.0# AUTHOR:       Xin23   http://weibo.com/231988while read IPdo        /home/u25151/upload.sh $IPdone

4.分发工具upload.sh

#!/usr/bin/expect# Version 1.0# AUTHOR:       Xin23   http://weibo.com/231988set timeout 3set USER u25151set PASSWORD xxxset IP [lindex $argv 0]spawn scp /tmp/scp.sh $USER@$IP:/tmpexpect {                "(yes/no)?" {send "yes\r"}                "*assword:" {send "$PASSWORD\r"}}expect {                "$" {send "\r"}                "*assword:" {send "$PASSWORD\r"}        }exit

5.发布执行命令脚本

#!/usr/bin/expect# Version 1.0# AUTHOR:       Xin23   http://weibo.com/231988set timeout 3set USER u25151set PASSWORD xxxset IP [lindex $argv 0]spawn ssh $USER@$IP /home/u25151/Collect_AIXInfo.shexpect {                "(yes/no)?" {send "yes\r"}                "*assword:" {send "$PASSWORD\r"}}expect {                "$" {send "\r"}                "*assword:" {send "$PASSWORD\r"}        }exit

THE END