#!/bin/bash
#系统名称;
s_type=$(uname -o | awk '{print " | "$0}')
#系统位数;32/64
os_bit=$(uname -m | awk '{print " | "$0}')
#内核发型版本
kernal_version=$(uname -r | awk '{print " | "$0}')
#系统版本信息
sys_info=$(cat /etc/issue | awk '{if($0 ~ /^\w/){print " | "$0}}')
#物理CPU个数:
cpu_actual_number=$(cat /proc/cpuinfo| grep "physical id"| sort| uniq| wc -l | awk '{print " | "$0}')
#逻辑cpu个数:
cpu_virtal_number=$(cat /proc/cpuinfo| grep "processor"| wc -l | awk '{print " | "$0}')
#cpu型号
cpu_version=$(cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c | awk '{for(i=2; i<=NF; i++){printf $i" "}}' | awk '{print " | "$0}' )
#内存:
mem_info_total=$(free -h | awk '{print " | "$0}' )
#联网情况:
net_conditon=$(ping -c 1 baidu.com | grep ttl | wc -l)
#磁盘信息:
disk_info=$(fdisk -l | grep "Disk /dev" | awk '{print " | "$0}' )
disk_info_using=$(df -h)
#主机名称
htname=$(hostname | awk '{print " | "$0}')
#网卡列表
eth_list=$(ip addr | awk '{if($0 ~ /^[0-9]\:(.*)$/){print $2}}' | cut -d ":" -f 1 | awk '{print " | "$0}')
#IP信息
ip_list=$(ip addr | grep -E 'inet\b' | awk '{print $2}' | cut -d "/" -f 1 | awk '{print " | "$0}')
echo -e "\n\n"
echo " 系统基本信息"
echo "---------------------------------------------------------------------------------------"
echo "系统名称:$os_type"
echo "主机名称: $htname"
echo "系统位数: $os_bit"
echo "内核版本:$kernal_version"
echo "系统版本: $sys_info"
echo "物理CPU个数:$cpu_actual_number"
echo "逻辑CPU个数:$cpu_virtal_number"
echo "CPU型号:$cpu_version"
echo "网卡列表:"
ip addr | awk '{if($0 ~ /^[0-9]\:(.*)$/){print $2}}' | cut -d ":" -f 1 | awk '{print " | "$0}'
echo "IP"
ip addr | grep -E 'inet\b' | awk '{print $2}' | cut -d "/" -f 1 | awk '{print " | "$0}'
echo "内存信息"
free -h | awk '{print " | "$0}'
echo "磁盘信息"
fdisk -l | grep "Disk /dev" | awk '{print " | "$0}'
#df -h
输出格式
系统基本信息
---------------------------------------------------------------------------------------
系统名称:
主机名称: | ubuntu
系统位数: | x86_64
内核版本: | 5.15.0-107-generic
系统版本:
物理CPU个数: | 2
逻辑CPU个数: | 4
CPU型号: | 11th Gen Intel(R) Core(TM) i5-11400 @ 2.60GHz
网卡列表:
| lo
| ens33
| docker0
| flannel.1
| cni0
| veth63728ac9@if2
| vethee22465e@if2
| vethade4959c@if2
| vethaaa2111d@if2
IP
| 127.0.0.1
| 192.168.252.128
| 172.17.0.1
| 10.42.0.0
| 10.42.0.1
内存信息
| total used free shared buff/cache available
| Mem: 11Gi 1.7Gi 7.1Gi 26Mi 3.0Gi 9.8Gi
| Swap: 0B 0B 0B
磁盘信息
| Disk /dev/loop0: 4 KiB, 4096 bytes, 8 sectors
| Disk /dev/loop1: 45.22 MiB, 47407104 bytes, 92592 sectors
| Disk /dev/loop2: 44.7 MiB, 46858240 bytes, 91520 sectors
| Disk /dev/loop3: 103.102 MiB, 109043712 bytes, 212976 sectors
| Disk /dev/loop4: 63.97 MiB, 67051520 bytes, 130960 sectors
| Disk /dev/loop5: 63.97 MiB, 67051520 bytes, 130960 sectors
| Disk /dev/loop6: 105.42 MiB, 110526464 bytes, 215872 sectors
| Disk /dev/loop7: 74.22 MiB, 77819904 bytes, 151992 sectors
| Disk /dev/sda: 40 GiB, 42949672960 bytes, 83886080 sectors
| Disk /dev/sdb: 50 GiB, 53687091200 bytes, 104857600 sectors
| Disk /dev/loop8: 349.71 MiB, 366682112 bytes, 716176 sectors
| Disk /dev/loop9: 504.16 MiB, 528642048 bytes, 1032504 sectors
| Disk /dev/loop10: 74.24 MiB, 77844480 bytes, 152040 sectors
| Disk /dev/loop11: 61.9 MiB, 64888832 bytes, 126736 sectors
| Disk /dev/loop12: 61.9 MiB, 64888832 bytes, 126736 sectors
| Disk /dev/loop13: 505.9 MiB, 529625088 bytes, 1034424 sectors
| Disk /dev/loop14: 349.71 MiB, 366678016 bytes, 716168 sectors
| Disk /dev/loop15: 91.7 MiB, 96141312 bytes, 187776 sectors
| Disk /dev/loop16: 12.33 MiB, 12922880 bytes, 25240 sectors
| Disk /dev/loop17: 12.95 MiB, 13553664 bytes, 26472 sectors
| Disk /dev/loop18: 38.75 MiB, 40615936 bytes, 79328 sectors
| Disk /dev/loop19: 38.85 MiB, 40714240 bytes, 79520 sectors
标签:脚本,sectors,MiB,bytes,dev,获取,awk,服务器,Disk
From: https://www.cnblogs.com/qcy-blog/p/18252917