Bash script code for obtaining computer hardware configuration information in Linux
Recently, to obtain the hardware configuration information of Several Linux servers, I wrote a script code to obtain the hardware configuration information, including the number of cpu cores, memory size, and hard disk size, the Code is as follows:
#! /Bin/bash
#
# Description:
# Used to get the hardware config information.
#
# History:
# Tcpipstack, 2012/09/04, created.
#
# Renewal #-----------------------------------------------------------------------------------------------------------------
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"
}
# Renewal #-----------------------------------------------------------------------------------------------------------------
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 logon and welcome information:/etc/issue,/etc/motd
Several common configuration files in Bash
Bash script 15-minute advanced tutorial
Job control instances of Bash and KSH shell in 10 Linux/Unix
Abnormal shell script running in Ubuntu: difference between Bash and dash
Bash script for statement if statement and various test statements
What is the Bash Shell build in command?
This article permanently updates the link address: