系统信息

测试版本:CentOS 6.5

#!/bin/bash

#=====variable
color_file=//tmp/CRT_XSHELL/system/color.lib

#=====judeg
function judge() {
	[ $UID -ne 0 ] && red "Please login root!" && exit 0
	if [ -f ${color_file} ] ;then . $color_file ;else echo "Please change $0 or add color file.";exit 0 ;fi
}
judge

#=====main body
function menu() {
#cat <<EOF
	local   a=$(echo $((RANDOM%6)))
        	echo -e "\033[3${a/0/3}m
		================================NENU==========================
		== 1.System biref information.  |==| 2.System resources.    ==
		== 3.CPU information.           |==| 4.Memory information.  ==
		== 5.Fdisk partition.   	|==| 6.Fdisk usage.         ==
		== 7.I/O information.	        |==| 8.IP address	    ==
		== 9.Network infornation.				    ==
		== 10.File or directory   detailed information.   	    ==
		== 11.System details information menu.			    ==
		== q.Exit.		        |===| p.Print Menu.	    ==
		==============================================================
		\033[0m"
#EOF
}
menu

function sys_1() {
	local	version=$(head -1 /etc/issue) #lsb_release -a
	local	host_name=$(uname -n) #hostname
	local	Kernel_version=$(uname -r) #sar -u 1 1 |awk 'NR==1{print $2}'
printf "%-s\t\t\t%-s\t\t%-s\n" System-version  Kernal-version Hostname
printf "%-s\t%-s\t%-s"  ${version} ${Kernel_version} ${host_name}
echo 
}

function top_2() {
	top -1 | head -4
}

function cpu_3() {
	cat /proc/cpuinfo | grep name  |cut -f2 -d: | uniq -c  #cpu型号
	local	c=`cat /proc/cpuinfo |egrep  "^physica" | sort|uniq|wc -l`;echo -e "physical of num\t: ${c} " #物理CPU个数
	cat /proc/cpuinfo | grep "cpu cores" | uniq #每个物理CPU的核数
	local	d=`cat /proc/cpuinfo |egrep  "^processor"|sort|uniq|wc -l`;echo -e "processor of num: ${d}"  #逻辑CPU个数
	cat /proc/cpuinfo |egrep  "^siblings" |uniq #每个逻辑CPU核数
	local a=$(cat /proc/cpuinfo | grep -e "cpu cores"  -e "siblings"|awk  'BEGIN{FS=":"}FNR==1{print $2}')
	local b=$(cat /proc/cpuinfo | grep -e "cpu cores"  -e "siblings"|awk  'BEGIN{FS=":"}FNR==2{print $2}')
	[ $a -ne $b  ] && echo "Hyperthreading is enabled"   #启用了超线程
}

function memory_4() {
	colo_r green "output in MB"
	free -m	#-h
}

function fdisk_5() {
#	MAJ:MIN 主\次设备号 RM 可卸载  RO只读
	/bin/lsblk # iostat  -p	
}

function fdisk_6() {
	/bin/df -Th
}

function io_7() {
	iostat -x
}

function network_8() {
	ip addr #ifconfig
}

function network_9() {
	local a b=$(ip addr|awk 'BEGIN{FS=":"}/mtu/{print $2}') c
	colo_r green "Network Name list:";echo -e "$b"
	read -p "Please input  network name : " a
	for i in ${b} ;do
		if [ "${a}" == "${i}" ] ;then 
			c=0;ethtool ${a};break
		else
			c=1	
		fi
	done	
	[ ${c} -eq 1 ]  && colo_r red "Network name error,exit!"
}

function fd_10() {
	local path a
	read -p "Please Input Path: "  path
	a=$(expr length "$path")
	if [ ${a} -ne 0 ] ;then
		if [ -f ${path}  -o -d ${path} ] ;then stat ${path} ;else colo_r red "${path} No such file or directory" ;fi
	else
		colo_r red "path is empty"
	fi
}

function system_menu() {
        local   a=$(echo $((RANDOM%6)))
        echo -e "\033[3${a/0/3}m
        0 BIOS                                  1 System                        2 Base Board                    
        3 Chassis                               4 Processor                     5 Memory Controller
        6 Memory Module                         7 Cache                         8 Port Connector        
        9 System Slots                          10 On Board Devices             11 OEM Strings                  
        12 System Configuration Options         13 BIOS Language                14 Group Associations           
        15 System Event Log                     16 Physical Memory Array        17 Memory Device        
        18 32-bit Memory Error                  19 Memory Array Mapped Address  20 Memory Device Mapped Address
        21 Built-in Pointing Device             22 Portable Battery             23 System Reset                 
        24 Hardware Security                    25 System Power Controls        26 Voltage Probe
        27 Cooling Device                       28 Temperature Probe            29 Electrical Current Probe
        30 Out-of-band Remote Access            31 Boot Integrity Services      32 System Boot                  
        33 64-bit Memory Error                  34 Management Device            35 Management Device Component  
        36 Management Device Threshold Data     37 Memory Channel               38 IPMI Device                  
        39 Power Supply                         40 Additional Informatio41 Onboard Device       41 Onboard Device
	b   Returns the next level		p  Print system menu  		q  Exit
        \033[0m"
}

function system_11() {
	local a
	system_menu
	colo_r fate_flash "Please input system details menu num: " ;read a
	if [ `expr ${a} + 0 2>/dev/null`  ] ;then 
		if [ ${a} -ge 0 -a ${a} -le 41 ] ;then 
			dmidecode -t ${a} 
		else
			colo_r red "menu num not in scope";exit 0
		fi
	else
		if [ ${a} == "b"  ] ;then
			menu;input
		elif [ ${a} == "p"  ] ;then
			system_menu;system_11
		elif [ ${a} == "q"  ] ;then
			exit 0
		else
			colo_r red "System info menu num not in the range" 
		fi
	fi
}

function input() {
	local a
	colo_r fate_flash "Please Input Menu Num: " ;read a
	case ${a} in
	1)	sys_1;input	;;
	2)	top_2;input	;;
	3)	cpu_3;input	;;
	4)	memory_4;input	;;
	5)	fdisk_5;input	;;
	6)	fdisk_6;input	;;
	7)	io_7;input	;;
	8)	network_8;input	;;	
	9)	network_9;input	;;
	10)	fd_10;input	;;
	11)	system_11	;;
	q)	exit 0		;;
	p)	menu;input	;;
	*)
		colo_r red "Menu Mun Error;Please Again"
		echo  " == p.Print Menut==";input
	esac
}
input
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值