Shell写的检测Linux系统硬件信息的脚本
这里是很久之前用shell写的一个linux系统硬件信息检测脚本,可以对照看一下。检测内容基本一样:操作系统信息、内存、CPU、硬盘分区及挂载情况,网卡配置情况、安装的软件信息等。
- #!/bin/bash
- #This script is used to check the server
- #system info
- system_info() {
- echo "**********************************************"
- echo "system info:"
- echo
- echo " System-release : `cat /etc/RedHat-release`"
- echo " Kernel-release : `uname -a|awk '{print $1,$3}'`"
- echo " Server-Model : `dmidecode | grep "Product Name:"|sed -n '1p'|awk -F': ' '{print $2}'`"
- echo
- }
- #CPU info
- cpu_info() {
- echo "**********************************************"
- echo "CPU info:"
- echo
- echo " Frequency : `cat /proc/cpuinfo | grep "model name" | uniq |awk -F': ' '{print $2}'`"
- echo " CPU cores: `cat /proc/cpuinfo | grep "cpu cores" | uniq |awk -F': ' '{print $2}'`"
- echo " Logic Count : `cat /proc/cpuinfo | grep "processor" | sort -u| wc -l `"
- echo " Physical Count : `cat /proc/cpuinfo | grep "physical" | sort -u| wc -l`"
- echo " Cache size : `cat /proc/cpuinfo| grep "cache size"|uniq|awk '{print $4,$5}'`"
- echo
- }
- #memory info
- mem_info() {
- memory=`dmidecode |grep "Range Size"|head -1|awk '{print $3$4}'`
- mem_size=`echo "This server has ${memory} memory."`
- echo "**********************************************"
- echo "Memory info:"
- echo
- echo " Total : ${mem_size}"
- echo " Count : `dmidecode |grep -A16 "Memory Device$"|grep Size|awk '{if($2!~/No/) print $0}'|wc -l`"
- dmidecode |grep -A20 "Memory Device$"|grep Size|sed '{s/^ */ /g};{/No/d}'
- echo
- }
- #disk and partitions
- swap_pos=`cat /proc/swaps|sed -n '2p'|awk '{print $1}'`
- partition_info() {
- echo "**********************************************"
- echo "Hard disk info:"
- echo
- echo "`fdisk -l|grep Disk|awk -F, '{print $1}'`"
- echo "**********************************************"
- echo "Partition info:"
- echo
- df -h | grep -v Filesystem | sed "s:none:${swap_pos}:"
- echo
- }
- #network adapter info
- adapter_info() {
- duplex_eth0=`ethtool eth0 | grep Duplex | awk '{if($2~/Full/) print "Full"};{if($2~/Half/)print "Half"};{if($2~/Uknown!/) print "unknown"}'`
- duplex_eth1=`ethtool eth1 | grep Duplex | awk '{if($2~/Full/) print "Full"};{if($2~/Half/)print "Half"};{if($2~/Uknown!/) print "unknown"}'`
- Negotiation_eth0=`ethtool eth0 | grep "Advertised auto-negotiation"|awk -F': ' '{if($2~/No/) print "Non-negotiation."};{if($2~/Yes/) print "Negotiation"}'`
- Negotiation_eth1=`ethtool eth1 | grep "Advertised auto-negotiation"|awk -F': ' '{if($2~/No/) print "Non-negotiation"};{if($2~/Yes/) print "Negotiation"}'`
- IP_eth0=`cat /etc/sysconfig/network-scripts/ifcfg-eth0|grep IPADDR|awk -F= '{print $2}'`
- IP_eth1=`cat /etc/sysconfig/network-scripts/ifcfg-eth1|grep IPADDR|awk -F= '{print $2}'`
- speed_eth0=`ethtool eth0|grep Speed|awk '{print $2}'`
- speed_eth1=`ethtool eth1|grep Speed|awk '{print $2}'`
- echo "**********************************************"
- echo "Network adapter info:"
- echo
- echo " IP_eth0 : ${IP_eth0} IP_eth0 : ${IP_eth1}"
- echo " Speed_eth0 : ${speed_eth0} Speed_eth1 : ${speed_eth1}"
- echo " Duplex_eth0 : ${duplex_eth0} Duplex_eth1 : ${duplex_eth1}"
- echo " Negotiation_eth0 : ${Negotiation_eth0} Negotiation_eth1 : ${Negotiation_eth1}"
- echo
- }
- #software package
- software_info() {
- echo "**********************************************"
- echo "SELinux is `cat /etc/selinux/config |grep SELINUX=disabled|awk -F= '{print $2}'||echo "enabled"`"
- echo "`service iptables status|sed 's/Firewall/Iptables/g'`"
- echo
- echo "**********************************************"
- sed -n '/%packages/,/%post/p;' /root/anaconda-ks.cfg|sed '/%post/d;/^$/d'
- echo "**********************************************"
- }
- #del mac-addr
- #sed -i '/HWADDR/d' /etc/sysconfig/network-scripts/ifcfg-eth0
- #sed -i '/HWADDR/d' /etc/sysconfig/network-scripts/ifcfg-eth1
- system_info
- cpu_info
- mem_info
- partition_info
- adapter_info
- software_info
相关推荐
彼岸随笔 2020-10-20
yutou0 2020-10-17
jarrygao 2020-11-02
shipinsky 2020-09-23
touchfuture 2020-09-16
hongsheyoumo 2020-09-04
卖口粥湛蓝的天空 2020-09-15
tianhuak 2020-11-24
huha 2020-10-16
lianshaohua 2020-09-23
laisean 2020-11-11
zhangjie 2020-11-11
大牛牛 2020-10-30
firefaith 2020-10-30
liguojia 2020-10-20
wangzhaotongalex 2020-10-20
以梦为马不负韶华 2020-10-20
CARBON 2020-10-20
lianshaohua 2020-10-20