Skip to content

Instantly share code, notes, and snippets.

@shalk
Last active November 4, 2017 04:36
Show Gist options
  • Save shalk/9382089 to your computer and use it in GitHub Desktop.
Save shalk/9382089 to your computer and use it in GitHub Desktop.
硬件信息采集 information collection
#!/bin/bash
#
# Function:
# This script can collect Infomation of System OS,CPU,MEM,DISK,NETWORK,and so on.
#
# I modify the script from a example from internet
# Thanks to the origin author.
# Have Fun!
# 2014-04-23 by shalk
# Todo :
# add eth link status
# add ipmi info
function print_base() {
echo -e "====================================="
echo -e "${Line}\nOS:\n${OS}\n${Line}"
echo -e "OS_version:\n${OS_version}\n${Line}"
echo -e "Kernel_version:\n${kernel_version}\n${Line}"
echo -e "====================================="
echo -e "CPU model:\n${CPU}\n${Line}"
echo -e "Total of physical CPU:\n${Counts}\n${Line}"
echo -e "Number of CPU cores\n${Cores}\n${Line}"
echo -e "Number of logical CPUs:\n${PROCESSOR}\n${Line}"
echo -e "Present Mode Of CPU:\n${Mode}\n${Line}"
echo -e "Support Mode Of CPU:\n${lm}\n${Line}"
echo -e "====================================="
echo -e "Total Memory:\n${Total}\n${Line}"
echo -e "Total Swap:\n${SwapTotal}\n${Line}"
echo -e "Buffers:\n${Buffers}\n${Line}"
echo -e "Cached:\n${Cached}\n${Line}"
echo -e "Available Memory:\n${Available} MB\n${Line}"
echo -e "Maxinum Memory Capacity:\n${Max_Capacity}\n${Line}"
echo -e "Number of Physical Memory:\n${Number}\n${Line}"
echo -e "====================================="
echo -e "Amount Of Disks:\n${Disk}\n${Line}"
echo -e "Disk Manufactor Info:\n${DiskInfo}\n${Line}"
echo -e "Usage Of partions:\n${Partion}\n${Line}"
echo -e "Disk Corespond:\n${DiskCorespond}\n${Line}"
echo -e "====================================="
echo -e "Network Config:\n${EthConfig}\n${Line}"
echo -e "Network Lspci:\n${EthPci}\n${Line}"
echo -e "Network Corespond:\n${NetCorespond}\n${Line}"
echo -e "====================================="
echo -e "RAID CARD:\n${RaidCard}\n${Line}"
echo -e "HBA CARD:\n${HbaCard}\n${Line}"
echo -e "SAS CARD:\n${SasCard}\n${Line}"
echo -e "SATA INTERFACE:\n${SataCard}\n${Line}"
echo -e "====================================="
}
# System
#if [[ -f /usr/bin/lsb_release ]]; then
#OS=$(/usr/bin/lsb_release -a |grep Description |awk -F : '{print $2}' |sed 's/^[ \t]*//g')
#fi
OS=$(cat /etc/issue | grep -v '^$' |awk -F '-' '{print $1}')
OS_version=$(uname -m)
kernel_version=$(uname -r)
# CPU
CPU=$(grep 'model name' /proc/cpuinfo |uniq |awk -F : '{print $2}' |sed 's/^[ \t]*//g'|sed 's/ \+/ /g')
Counts=$(grep 'physical id' /proc/cpuinfo |sort |uniq |wc -l)
Cores=$(grep 'cpu cores' /proc/cpuinfo |uniq |awk -F : '{print $2}' |sed 's/^[ \t]*//g')
PROCESSOR=$(grep 'processor' /proc/cpuinfo |sort |uniq |wc -l)
Mode=$(getconf LONG_BIT)
Numbers=$(grep 'lm' /proc/cpuinfo |wc -l)
if (( ${Numbers} > 0)); then lm=64
else lm=32
fi
#MEM
Total=$(cat /proc/meminfo |grep 'MemTotal' |awk -F : '{print $2}' |sed 's/^[ \t]*//g')
Number=$(dmidecode | grep -A16 "Memory Device$" |grep Size|sort |sed 's/^[ \t]*//g')
SwapTotal=$(cat /proc/meminfo |grep 'SwapTotal' |awk -F : '{print $2}' |sed 's/^[ \t]*//g')
Buffers=$(cat /proc/meminfo |grep 'Buffers' |awk -F : '{print $2}' |sed 's/^[ \t]*//g')
Cached=$(cat /proc/meminfo |grep '\<Cached\>' |awk -F : '{print $2}' |sed 's/^[ \t]*//g')
Available=$(free -m |grep - |awk -F : '{print $2}' |awk '{print $2}')
Max_Capacity=$(dmidecode -t memory -q |grep 'Maximum Capacity' |awk -F : '{print $2}' |sed 's/^[ \t]*//g')
#DISK
Disk=$(fdisk -l 2>/dev/null |grep 'Disk' |awk -F , '{print $1}')
DiskInfo=$(ls /dev/sd* | sort | grep -v '[0-9]' | xargs -I {} smartctl -i {} | grep -e '^Device:' -e '^Serial' -e '^Trans')
Partion=$(df -hlP |sed -n '2,$p')
DiskCorespond=$(ls -l /sys/class/block/sd* )
#NETWORK
EthConfig=$(ifconfig -a | grep "^\w" -A 1)
EthPci=$(lspci -v | grep Eth -i)
NetCorespond=$(ls -l /sys/class/net/)
#EthLink=$(ethtool)
#RAID CARD or HBA CARD
SasCard=$(lspci -v | grep SAS -i )
SataCard=$(lspci -v | grep SATA -i )
RaidCard=$(lspci -v | grep Raid -i )
HbaCard=$(lspci -v | grep HBA -i )
Line='==========='
print_base
exit
#/etc/init.d/ipmi status 2>&1 >/dev/null
#if /etc/init.d/ipmi status 2>&1 >/dev/null
#then
# echo
#else
# IPMI_INFO="IPMI is not exist!\n"
#fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment