Linux下擷取電腦硬體設定資訊的bash指令碼代碼

來源:互聯網
上載者:User

Linux下擷取電腦硬體設定資訊的bash指令碼代碼

最近由於要擷取幾台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 

Bash常用的幾個設定檔

Bash指令碼15分鐘進階教程

10個 Linux/Unix下 Bash 和 KSH shell 的作業控制執行個體

Ubuntu下shell指令碼運行異常:Bash和dash的區別

Bash指令碼之for語句if語句以及各種測試語句

什麼是Bash Shell的內建(build in)命令

本文永久更新連結地址:

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.