shell实现自动查询CPU-内存-系统版本并输出
function FUNCRIONOS(){
PLATFORM=`/bin/uname`
case $PLATFORM in
HP-UX)
os=HP-UX ;;
AIX)
os=AIX ;;
SunOS)
os=SunOS ;;
Linux)
if [ -s /etc/oracle-release ]; then
os=Oracle
elif [ -s /etc/SuSE-release ]; then
os=SuSE
elif [ -f /etc/centos-release ]; then
os=CentOS
elif [ -s /etc/redhat-release ]; then
os=RedHat
elif [ -r /etc/os-release ]; then
grep 'NAME="Ubuntu"' /etc/os-release > /dev/null 2>&1
if [ $? == 0 ]; then
os=Ubuntu
fi
else
os="Unknown Linux"
fi ;;
*)
os="Unknown UNIX/Linux" ;;
esac
echo $os
}
OS=`FUNCRIONOS`
case ${OS} in
CentOS)
VERSION=`cat /etc/issue | grep '6.'`
if [ "$VERSION" == "" ];then
VERSION='7'
else
VERSION='6'
fi
;;
RedHat)
VERSION=`cat /etc/issue | grep '6.'`
if [ "$VERSION" == "" ];then
VERSION='7'
else
VERSION='6'
fi
;;
*)
echo "${OS} may be unsupport."
exit
;;
esac
cpu=`cat /proc/cpuinfo | grep "model\\ name" | awk -F':' '{print $2}' | grep -c ''`
mem=`free -g | grep Mem | awk '{print$2}'`
disk=`df -Ph . | sed -n '2p' | awk '{print$4}'`
os="${OS} ${VERSION}"
echo -e "\033[32m #################当前系统信息如下:#################\033[0m"
echo -e "\033[32m ~~~~~~~~~~~~~~TIME: `date`~~~~~~~~~~~~~\033[0m"
echo -e "\033[32m ###########CPU: ${cpu}C###########\033[0m"
echo -e "\033[32m ###########MEM: ${mem}G###########\033[0m"
echo -e "\033[32m ###########HDD: ${disk}###########\033[0m"
echo -e "\033[32m ###########OS: ${os} ###########\033[0m"