DeniseJoe
作者DeniseJoe·2012-03-06 16:02
系统架构师·IBM

小小的share-AIX 系统信息收集shell

字数 2234阅读 2709评论 0赞 1

最近组织部门同事学习AIX和shell脚本,出了一个小练习题目,下面把自己的脚本贴出来纪念一下:

题目:编写脚本统计当前AIX系统的基本配置信息,具体命令自定。输出结果为:

Below is the configure information of Server :XXXXX(server name)
Mem(Unit)     CPU      Disk(Unit)
X                    X          X

实现: Serverinfo.ksh 

#! /usr/bin/ksh
#***************************************************
#Date: 2012-03-02
#Description: This shell is used to get the base infomation on AIX
#*****************************************************

#***************************************************

#0. Defined paremeters

#***************************************************
export diskspace=0
mem=0
cpu=0
server_name=""
file_sysconfinfo=/tmp/serverinfo.txt

#***************************************************

#1. Get the information about CPU and memory

#***************************************************

prtconf > ${file_sysconfinfo}

mem=$(grep 'Good Memory Size' ${file_sysconfinfo} | awk '{print $4 $5}')
cpu=$(grep 'Number Of Processors' ${file_sysconfinfo} | awk '{print $4}')
server_name=$(hostname)

#***************************************************

#2. Get the disk information

#***************************************************
function GetDisk {
file_diskinfo=/tmp/diskinfo
file_pvinfo=/tmp/pvinfo

if [[ -f ${file_diskinfo} ]]

then

cp ${file_diskinfo} ${file_diskinfo}.cp
rm -rf ${file_diskinfo}
fi
touch ${file_diskinfo}

if [[ -f ${file_pvinfo} ]]

then

cp ${file_pvinfo} ${file_pvinfo}.cp
rm -rf ${file_pvinfo}
fi
touch ${file_pvinfo}

lspv > ${file_pvinfo}
diskname=""

while read line
do
diskname=$( echo ${line} |awk '{print $1}')
lscfg -l $diskname|sed 's/.*((.*)).*/1/' >> ${file_diskinfo}
done <${file_pvinfo}

while read line
do
tempdisk=$(echo ${line} | awk '{print $1}')
((diskspace=$diskspace+$tempdisk))
done <${file_diskinfo}
export diskspace
}

 

#***************************************************
#3.Print the result at screen

#***************************************************

GetDisk
printf "Below is the configure infomation of server:%sn" $server_name
printf "%-15s%-15s%-15sn" "Memory(MB)" "CPU" "Disk(MB)" $mem $cpu $diskspace

 

如果觉得我的文章对您有用,请点赞。您的支持将鼓励我继续创作!

1

添加新评论0 条评论

Ctrl+Enter 发表

作者其他文章

X社区推广