最近由於要獲取幾台Linux服務器的硬件配置信息,就寫了一個獲取硬件配置信息的腳本代碼,可以獲取cpu核心數、內存大小、硬盤大小信息,代碼如下所示:
#!/bin/bash
#
# Description:
# Used to get the hardware config information.
#
# History:
# tcpipstack, 2012/09/04, created.
#
#-----------------------------------------------------------------------------------------------------------------
fn_get_cpu_info()
{
echo -e "\n CPU Num is: "`grep -c 'model name' /proc/cpuinfo`
echo "`cat /proc/cpuinfo | grep processor | wc -l`"
#echo `cat /proc/cpuinfo | grep 'model name' | sed 's'`
}
fn_get_disk_info()
{
echo -e "\n Disk Information: "
for x in `df -h | grep /dev | awk '{print $5 "-" $6 "-" $2 "-" $4}' | sed 's/%//g'`
do
disk_status=(${x//"-"/" "})
echo "Disk Directory ${disk_status[1]} DiskTotal=${disk_status[2]} DiskUsed=${disk_status[3]}"
done
}
fn_get_mem_info()
{
MemTotal=`free -m | grep Mem | awk '{print $2}'`
echo -e "\n Memory is: ${MemTotal} MB "
}
#-----------------------------------------------------------------------------------------------------------------
echo -e "\n -----------This Computer's Hardware Config Information is: -----------\n"
fn_get_disk_info
fn_get_cpu_info
fn_get_mem_info
echo -e "\n -----------End -----------\n"
bash的登錄與歡迎信息:/etc/issue,/etc/motd http://www.linuxidc.com/Linux/2014-08/105419.htm
Bash常用的幾個配置文件 http://www.linuxidc.com/Linux/2014-08/105202.htm
Bash腳本15分鐘進階教程 http://www.linuxidc.com/Linux/2014-04/100750.htm
10個 Linux/Unix下 Bash 和 KSH shell 的作業控制實例 http://www.linuxidc.com/Linux/2014-03/98159.htm
Ubuntu下shell腳本運行異常:Bash和dash的區別 http://www.linuxidc.com/Linux/2013-10/91100.htm
Bash腳本之for語句if語句以及各種測試語句 http://www.linuxidc.com/Linux/2013-07/87922.htm
什麼是Bash Shell的內建(build in)命令 http://www.linuxidc.com/Linux/2013-06/86039.htm