快速查看Linux系统硬件信息及负载

  • 生产实践:

    查看系统的基础信息及负载,用于系统排错等

  • 学习技巧:

    cut、dmidecode、egrep等使用

  • 脚本内容:      

#!/bin/bash
############################################################
# $Name:         system_info.sh
# $Version:      v1.0
# $Function:     For view the system basic information
# $Author:       Zhihe An
# $Copyright (c) https://chegva.com
# $Create Date:  2018-07-25
############################################################

sys(){
echo -e '\n=========system:========='
dmidecode -t system |egrep "Manufacturer|Product Name" |xargs echo;
uname -a|cut -d ' ' -f 2|sed s/^/HostName:' '/;hostname -I|sed s/^/IP:' '/;cat /etc/redhat-release |sed s/^/System:' '/;uname -a|cut -d ' ' -f 3|sed s/^/Kernel:' '/;uptime |sed s/^/Uptime:' '/;
echo -e '\n=========CPU:========='
cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c
lscpu |egrep -v 'Order|Vendor|Model|Stepping|BogoMIPS|family|On-line|op-mode|CPU\ socket|NUMA\ node' | perl -pe 's/(CPU\(s\))/\e[1;31m$1\e[0m/ig'
echo -e '\n=========内存:========='
dmidecode |grep 'Range Size' | awk '{sub(/^[ \t]+/,"");print $0}'
MEM_TOTAL=`free -m |awk '{if(NR==2)printf "%.1f",$2/1024}END{print "G"}'`
USE=`free -m |awk '{if(NR==3) printf "%.1f",$3/1024}END{print "G"}'`
FREE=`free -m |awk '{if(NR==3) printf "%.1f",$4/1024}END{print "G"}'`
CACHE=`free -m |awk '{if(NR==2) printf "%.1f",($6+$7)/1024}END{print "G"}'`
echo -e "Total: \033[31m$MEM_TOTAL\033[0m"
echo -e "Use: \033[31m$USE\033[0m"
echo -e "Free: $FREE"
echo -e "Cache: $CACHE"
free -m
echo -e '\n=========磁盘:========='
cat /etc/fstab |egrep -v "^(#|$|[ ]*#)";echo;lsblk;echo;df -TH
echo -e '\n=========网卡:========='
lspci -vvv |grep Ethernet
echo
ifconfig -a |awk -F'[: ]+' '{print $1}' |xargs echo
echo
route -n;echo;route |grep default
echo -e '\n=========连接:========='
netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}';echo -e '\n=======top10K======='; netstat -na|grep ESTABLISHED|grep -v 127.0.0.1|awk '{print $5}'|awk -F: '{print $1}'|sort|uniq -c|sort -rn |head |xargs -n1 -r -i bash -c "echo -n {};echo  {}|awk '{ print \$2 }'|xargs host |awk -v OFS=' ' '{ print \$10,\$NF }'";echo -e '\n=======handle=======';lsof -n |awk '{print $2}'|sort|uniq -c |sort -nr|head
echo -e '\n=========top5-cpu:========='
ps auxw|head -1|perl -pe 's/(%cpu)/\e[1;31m$1\e[0m/ig';ps auxw|sort -rn -k3|head -5
echo -e '\n=========top5-mem:========='
ps auxw|head -1|perl -pe 's/(%mem)/\e[1;31m$1\e[0m/ig';ps auxf|sort -rn -k4|head -5
echo -e   '\n=========服务:========='
pstree;echo;service --status-all;echo
echo -e   '\n=========iptables:========='
iptables -nvL;echo
echo -e '\n=========crontab:========='
crontab -l;echo;
echo -e   '\n=========rc.local:========='
cat /etc/rc.local /etc/rc.d/rc.local | egrep -v "^(#|$|[ ]*#)"
echo -e '\n=========负载:========='
dstat -lcpdmsn 1 4
};clear;echo;sys

◎查看效果

快速查看Linux系统硬件信息及负载

快速查看Linux系统硬件信息及负载

anzhihe 安志合个人博客,版权所有 丨 如未注明,均为原创 丨 转载请注明转自:https://chegva.com/2955.html | ☆★★每天进步一点点,加油!★★☆ | 

您可能还感兴趣的文章!

发表评论

电子邮件地址不会被公开。 必填项已用*标注