获取当前设备信息shell函数
作者:邓聪聪#!/bin/bashPATH=$PAT
get_Info(){ IP=$( wget -qO- -t1 -T2 ipv4.icanhazip.com ) cname=$( awk -F: '/model name/ {name=$2} END {print name}' /proc/cpuinfo | sed 's/^[ \t]*//;s/[ \t]*$//' )
cpu=$( cat /proc/cpuinfo| grep "physical id"| sort| uniq| wc -l ) cores=$( cat /proc/cpuinfo| grep "cpu cores"| uniq|awk '{print $4}' ) freq=$( awk -F: '/cpu MHz/ {freq=$2} END {print freq}' /proc/cpuinfo | sed 's/^[ \t]*//;s/[ \t]*$//' ) tram=$( free -m | awk '/Mem/ {print $2}' ) swap=$( free -m | awk '/Swap/ {print $2}' ) up=$( awk '{a=$1/86400;b=($1%86400)/3600;c=($1%3600)/60;d=$1%60} {printf("%ddays, %d:%d:%d\n",a,b,c,d)}' /proc/uptime ) load=$( w | head -1 | awk -F'load average:' '{print $2}' | sed 's/^[ \t]*//;s/[ \t]*$//' ) os=$( awk '{print ($1,$3~/^[0-9]/?$3:$4)}' /etc/redhat-release ) arch=$( uname -m ) lbit=$( getconf LONG_BIT ) host=$( hostname ) kern=$( uname -r )
disk=$( fdisk -l |grep "Disk /dev/sda"|awk '{print $3,$4}'|cut -d, -f 1 ) echo "########## System Information ##########" echo echo "CPU model : ${cname}"
echo "CPU physical : ${cpu}" echo "Number of cores : ${cores}" echo "CPU frequency : ${freq} MHz" echo "Total amount of ram : ${tram} MB" echo "Total amount of swap : ${swap} MB"
echo "The Disk : ${disk}" echo "System uptime : ${up}" echo "Load average : ${load}" echo "OS : ${os}" echo "Arch : ${arch} (${lbit} Bit)" echo "Kernel : ${kern}" echo "Hostname : ${host}" echo "IPv4 address : ${IP}" echo echo "########################################" } get_Info