shell下获取硬件基本信息

shell下获取CPU型号,核心数,内存大小,磁盘信息,IP信息
本代码基于CentOS 6验证通过

#!/bin/sh

sysinfo(){
    echo "+--------------------------------------------------------------------+"
    echo "CPU: 
    `cat /proc/cpuinfo | grep 'model name' | awk -F ":" '{print$2}'| sed 's#^[ \t]*##g'` 核心数:`cat /proc/cpuinfo | grep processor | wc -l`" 
    echo "+--------------------------------------------------------------------+"
    echo "Mem: `free -m | sed -n '2p'|awk '{print$2}'` MB"
    echo "+--------------------------------------------------------------------+"
    echo -e "磁盘信息: \n`df -h`"
    echo "+--------------------------------------------------------------------+"
    echo -e "IP信息:\n`ifconfig -a | grep 'inet addr' | egrep -v '127' |awk -F ':' '{print$2}' | sed 's#[ \t].*##g'`"
    echo "+--------------------------------------------------------------------+"
}

sysinfo

QQ20180104-115222@2x