我是靠谱客的博主 能干网络,最近开发中收集的这篇文章主要介绍查看linux硬件信息脚本,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

查看linux硬件信息脚本

#!/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


转载于:https://blog.51cto.com/639216/1416385

最后

以上就是能干网络为你收集整理的查看linux硬件信息脚本的全部内容,希望文章能够帮你解决查看linux硬件信息脚本所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(49)

评论列表共有 0 条评论

立即
投稿
返回
顶部