Shell——查看基础信息脚本

文章目录

      • 脚本简介
      • 脚本注解
      • 安装方式
      • 执行方式
        • 执行结果
      • 脚本内容
        • 新版本
        • 旧版本

脚本简介

  1. 基于运维统一脚本中,19、脚本安装下的检查服务器脚本安装
  2. 使用yum安装(yum仓库),系统版本Centos7

脚本注解

  1. 该脚本为了快速查看Centos7服务器上的基础配置
  2. 基础配置:OS、CPU、Memory、DISK、Network 的基础配置信息
  3. 脚本在检查磁盘读写是需要安装sysstat,检查网络配置是需要安装net-tools安装包
  4. 脚本自动判断,如果没有安装,则退出脚本,提示需要安装对应的软件包

安装方式

cd /usr/local/bin
vim infosystem
...
# 保存退出后,赋予脚本可执行权限
chomd +x infosystem
  1. 脚本存放在/usr/local/bin/目录下,文件名: infosystem
  2. 存放完成后,添加可执行权限

执行方式

infosystem
  1. 在当前已安装的服务器上的任意路径输入infosystem
  2. 服务器上已安装bash-completion的则可使用tab键进行自动补全

执行结果

[root@localhost ~]# infosystem 
----------------------------------------------------------------------------------
系统基本信息
            系统: CentOS kvm x86_64
            主机: CentOS
            内核: Linux 3.10.0-957.21.3.el7.x86_64
            负载: 0.18, 0.35, 0.40
          主机名: ansible
      Shell 版本: 4.2.46(2)-release
          IP地址: 172.21.134.130 172.22.0.1 172.17.0.1 172.16.1.64 172.18.0.1 
----------------------------------------------------------------------------------
CPU的基本信息
       物理CPU数: 1
     逻辑CPU总数: 8
 CPU对应物理核数: 4
         CPU名称: Intel(R) Xeon(R) Platinum 8163 CPU @ 2.50GHz
----------------------------------------------------------------------------------
CPU使用状态(%)百分比
     用户空间占用CPU: 3.1 us	 IO等待占用CPU的百分比: 0.0 wa
     内核空间占用CPU: 2.3 sy			硬中断: 0.0 hi
  改变过优先级的进程: 0.0 ni			软中断: 0.0 si
       空闲CPU百分比: 94.6 id	     等待真实的cpu资源: 0.0 si
----------------------------------------------------------------------------------
内存基本信息
            总量: 15884MB
程序认为可用内存: 8510MB
    实际尚未使用: 394MB+8510MB=8904MB
      内存使用率: 43.94%
    交换分区总量: 0MB
  交换分区使用量: 0MB
----------------------------------------------------------------------------------
磁盘基本信息
名称     类型(SSD)             
vda        HDD                     
----------------------------------------------------------------------------------
名称                         大小        r/s       w/s       rkB/s     类型     
/dev/vda1                    107.4GB     0.87      9.38      46.79     ext4      
----------------------------------------------------------------------------------
网卡基本信息
网卡            IPV4            掩码            广播          接收数据包 发送数据包 IPV6                   
br-8dab7d403a06 172.22.0.1      255.255.0.0     172.22.255.255  0.0        0.0                                    
br-c1e26c782f89 172.18.0.1      255.255.0.0     172.18.255.255  0.0        0.0                                    
docker0         172.17.0.1      255.255.0.0     172.17.255.255  714.4      1.1                                    
eth0            172.21.134.130  255.255.240.0   172.21.143.255  7.2        734.8                                  
lo              127.0.0.1       255.0.0.0                       324.6      324.6                                             
tunl0           172.16.1.64     255.255.255.255                 0.0        0.0      

脚本内容

新版本

  1. 新版本新增中文注解,同时可通过脚本变量进行修改,默认中文,可执行修改
  2. 新增CPU使用状态内容
  3. 优化网卡的显示内容,(k8s安装calico生成的虚拟网卡除外)
#!/bin/bash
#所有者:北城半夏
#当前版本
#v1.0.1
#################################################################################
#English or Chinese
language="Chinese"
#################################################################################
info3(){
 echo -e "\033[36m----------------------------------------------------------------------------------\033[0m" 
}

info(){
 #系统
 system=$(hostnamectl | grep System | awk '{print $3}')
 kernel_release=$(hostnamectl | grep Kernel | awk -F : '{print $2}'|sed 's/^[ \t]*//g')
 Virtualization=$(hostnamectl | grep Virtualization | awk '{print $2}')
 server_name=$(hostname)
 ipaddr=$(hostname -I)
 #cpu
 Physical_CPUs=$(grep "physical id" /proc/cpuinfo| sort | uniq | wc -l)
 Virt_CPUs=$(grep "processor" /proc/cpuinfo | wc -l)
 CPU_Kernels=$(grep "cores" /proc/cpuinfo|uniq| awk -F ': ' '{print $2}')
 CPU_Type=$(grep "model name" /proc/cpuinfo | awk -F ': ' '{print $2}' | sort | uniq)
 CPU_Arch=$(uname -m)
 #负载
 update_load=`uptime | awk -F ":" '{print $NF}'|sed 's/^[ \t]*//g'`
 #bash
 bash_version=`bash --version|grep "GNU bash"|awk '{print $4}'`
 #内存
 MemTotal=$(grep MemTotal /proc/meminfo| awk '{print $2}') #KB
 MemFree=$(grep MemFree /proc/meminfo| awk '{print $2}') #KB
 MemAvailable=$(grep -i Cached /proc/meminfo | awk '{print $2}' |head -1) #KB
 SwapTotal=$(grep SwapTotal /proc/meminfo| awk '{print $2}')
 SwapFree=$(grep SwapFree /proc/meminfo| awk '{print $2}') #KB
 let MemUsed=MemTotal-MemFree
 MemPercent=$(awk "BEGIN {if($MemTotal==0){printf 100}else{printf \"%.2f\",$MemUsed*100/$MemTotal}}")
 report_MemTotal="$((MemTotal/1024))" #内存总容量(MB)
 report_MemFree="$((MemFree/1024))" #内存剩余(MB)
 report_MemAvai="$((MemAvailable/1024))" #使用中(MB)
 #swap
 report_swapTotal="$((SwapTotal/1024))""MB" #内存总容量(MB)
 report_swapFree="$((SwapFree/1024))""MB" #内存剩余(MB)
 let Memfree=MemAvailable+MemFree
 let MemUsed=MemTotal-Memfree
 report_Mem="$((Memfree/1024))""MB"
 report_MemUsedPercent="$(awk "BEGIN {if($MemTotal==0){printf 100}else{printf \"%.2f\",$MemUsed*100/$MemTotal}}")""%" #内存使用率%


}
pd_disk_ssd(){
 pd_ssd=`lsblk -d -o name|grep -v NAME`
 pd_TYPE=`lsblk -d -o rota|grep -v ROTA`
 for i in  ${pd_ssd};do pd_ssd_name[${#pd_ssd_name[*]}]=$i;done
 for i in  ${pd_TYPE};do pd_TYPE_name[${#pd_TYPE_name[*]}]=$i;done

if [ ${language} == "Chinese" ];then
      printf "\e[34m%-10s %-11s %-11s \e[0m\n" 名称 类型\(SSD\)
  elif [ ${language} == "English" ];then
      printf "\e[34m%-10s %-11s %-11s \e[0m\n" Disk_name Disk_Type\(SSD\)
fi


 local num1=$((`echo ${#pd_TYPE_name[*]}`-1))
 for pd in `seq 0 ${num1}`
   do
      if [ ${pd_TYPE_name[pd]} -eq 0 ];then
          printf "\e[36m%-10s %-11s %-11s \e[0m\n" ${pd_ssd_name[pd]} SSD
      elif [ ${pd_TYPE_name[pd]} -eq 1 ];then
          printf "\e[36m%-10s %-11s %-11s \e[0m\n" ${pd_ssd_name[pd]}  HDD
      fi
 done
 info3
}
#网卡信息
getnetworkstatus(){
 check_rpm_iostat net-tools
 local ifs=`ifconfig | egrep "^[a-z]"| egrep -v "^c|^v" |awk -F ':' '{print $1}'`
 echo -e "\033[36m网卡基本信息\033[0m" 
 local a=${ifs}
 local b=`for i in $a;  do  echo $(ifconfig ${i} |grep inet6 |awk '{print $2}') ;done`
 local ipv4=$(for i in $a;do echo "`ifconfig ${i} | awk 'NR==2{print $2}'`" ;done)
 local netmask=$(for i in $a ;do echo `ifconfig  $i|grep netmask|awk '{print $4}'` ;   done)
 local broadcast=$(for i in $a ;do echo `ifconfig  $i|grep broadcast|awk '{print $6}'` ;   done)
 local RX_packets=$(for i in $a ;do echo `ifconfig $i|grep "RX packets"|awk -F '(' '{print $2}'|cut -d ")" -f 1|awk '{print $1}'` ;   done)
 local TX_packets=$(for i in $a ;do echo `ifconfig $i|grep "TX packets"|awk -F '(' '{print $2}'|cut -d ")" -f 1|awk '{print $1}'` ;   done)
 local num=`for i in  ${ifs};do echo $i ;done |wc -l`
 local num_01=`for((i=0;i<$num;i++)); do echo $i; done`
  #ipv4
  for i in $ipv4 ;do  network_ipv4[${#network_ipv4[*]}]=$i ;done
  #ipv6
  for i in $b;  do network_ipv6[${#network_ipv6[*]}]=$i ; done
  #网卡名
  eth_name=(`echo ${ifs}`)
  #netmask 子网掩码
  for i in $netmask;  do network_netmask[${#network_netmask[*]}]=$i ; done
  #broadcast 默认网关
  for i in $broadcast;  do network_broadcast[${#network_broadcast[*]}]=$i ; done
  #RX packets 出流量
  for i in $RX_packets;  do network_RX_packets[${#network_RX_packets[*]}]=$i ; done
  #TX packets 进流量
  for i in $TX_packets;  do network_TX_packets[${#network_TX_packets[*]}]=$i ; done
if [ ${language} == "Chinese" ];then
      printf "\e[34m%-17s %-15s %-17s %-15s %-10s %-15s %-23s\e[0m\n"  网卡 IPV4 掩码 广播  接收数据包 发送数据包 IPV6
  elif [ ${language} == "English" ];then
      printf "\e[34m%-15s %-15s %-15s %-15s %-10s %-15s %-23s\e[0m\n"  Network IPV4 Netmask Broadcas  RX_packets TX_packets IPV6
fi
 for i in $num_01
  do
    if [ ${eth_name[i]} == lo ] || [ ${eth_name[i]} == tunl0 ];then
        printf "%-15s %-15s %-31s %-10s %-10s %-15s %-23s\n" ${eth_name[i]} ${network_ipv4[i]} ${network_netmask[i]}  ${network_RX_packets[i]} ${network_TX_packets[i]} ${network_ipv6[i]}
    else
        printf "%-15s %-15s %-15s %-15s %-10s %-15s %-23s\n" ${eth_name[i]} ${network_ipv4[i]} ${network_netmask[i]} ${network_broadcast[i]} ${network_RX_packets[i]} ${network_TX_packets[i]} ${network_ipv6[i]}
    fi
 done

}
############################################################################################################
disk_info(){
  #磁盘
 check_rpm_iostat sysstat
 disk_info=`blkid|awk -F':' '{print $1}'|grep -v sr0`
 for i in  ${disk_info};do disk_name[${#disk_name[*]}]=$i;done
 disk_type_info=`blkid|awk  '{print $1""$NF}'|grep -v sr0|awk -F'"' '{print $2}'`
 for i in  ${disk_type_info};do disk_type[${#disk_type[*]}]=$i;done
 num=$((`echo ${#disk_name[*]}`-1))
 for size in `seq 0 ${num}`
     do
       disk_size_array=`fdisk -l ${disk_name[size]}|grep Disk|awk '{print $3""$4}'|cut -d , -f 1`
       disk_size[${#disk_size[*]}]=$disk_size_array
       diskRead_writ_array=`iostat -d -x  ${disk_name[size]}| grep -v "^$"|tail -1|awk '{print $4"\t"$5"\t"$6}'`
       diskRead_writ[${#diskRead_writ[*]}]=${diskRead_writ_array}
 done
 echo -e "\033[36m磁盘基本信息\033[0m"
 pd_disk_ssd
if [ ${language} == "Chinese" ];then
    printf "\e[34m%-30s %-13s %-10s%-10s%-10s%-11s\e[0m\n" 名称 大小  r/s     w/s    rkB/s 类型
  elif [ ${language} == "English" ];then
    printf "\e[34m%-28s %-11s %-10s%-10s%-10s%-11s\e[0m\n" Disk_name Size  r/s     w/s    rkB/s Type
fi
 for i in `seq 0 $num`
   do
     printf "\e[32m%-28s %-10s  %-10s%-10s%-10s%-10s\e[0m\n" ${disk_name[i]} ${disk_size[i]}  ${diskRead_writ[i]} ${disk_type[i]}
  done
}
CPU_STATUS(){
  local status=`top -b -n 1|head |grep "%Cpu(s)"|cut -d : -f 2 |sed 's/^[ \t]*//g'`
  local user_cpu=`echo ${status}| awk -F ',' '{print $1}'`
  local kernel_CPUs=`echo ${status}| awk -F ',' '{print $2}'|sed 's/^[ \t]*//g'`
  local process_CPUs=`echo ${status} | awk -F ',' '{print $3}'|sed 's/^[ \t]*//g'`
  local free_CPUs=`echo ${status} | awk -F ',' '{print $4}'|sed 's/^[ \t]*//g'`
  local iowait=`echo ${status} | awk -F ',' '{print $5}'|sed 's/^[ \t]*//g'`
  local Hardware=`echo ${status} | awk -F ',' '{print $6}'|sed 's/^[ \t]*//g'`
  local Interrupts=`echo ${status} | awk -F ',' '{print $7}'|sed 's/^[ \t]*//g'`
  local real=`echo ${status} | awk -F ',' '{print $7}'|sed 's/^[ \t]*//g'`
  info3
 echo -e "\033[36mCPU使用状态(%)百分比\033[0m"
 if [ ${language} == "Chinese" ];then
       echo -e "     用户空间占用CPU: $user_cpu\t IO等待占用CPU的百分比: ${iowait}"
       echo -e "     内核空间占用CPU: $kernel_CPUs\t\t\t硬中断: ${Hardware}"
       echo -e "  改变过优先级的进程: $process_CPUs\t\t\t软中断: ${Interrupts}"
       echo -e "       空闲CPU百分比: $free_CPUs\t     等待真实的cpu资源: ${real}"
 elif [ ${language} == "English" ];then
       #English
       echo -e "       user_CPUs: $user_cpu    \t\t     IO Wait: ${iowait}"
       echo -e "     kernel_CPUs: $kernel_CPUs    \t\tHardware IRQ: ${Hardware}"
       echo -e "    process_CPUs: $process_CPUs\t\t Software Interrupts: ${Interrupts}"
       echo -e "       free_CPUs: $free_CPUs\t   Wait for real cpu: ${real}"
 fi
}
index_portal(){
  case $1 in 
    'cpu')
        if [ ${language} == "Chinese" ];then
             echo -e "\033[36m系统基本信息\033[0m"
             echo "            系统: ${system} ${Virtualization} ${CPU_Arch}"
             echo "            主机: ${system}"
             echo "            内核: ${kernel_release}"
             echo "            负载: ${update_load}"
             echo "          主机名: ${server_name}"
             echo "      Shell 版本: ${bash_version}"
             echo "          IP地址: ${ipaddr}"
             info3
             echo -e "\033[36mCPU的基本信息\033[0m"
             echo "       物理CPU数: $Physical_CPUs"
             echo "     逻辑CPU总数: $Virt_CPUs"
             echo " CPU对应物理核数: $CPU_Kernels"
             echo "         CPU名称: $CPU_Type"

         elif [ ${language} == "English" ];then
         #English
             echo -e "\033[36m系统基本信息\033[0m"
             echo "              OS: ${system} ${Virtualization} ${CPU_Arch}"
             echo "            Host: ${system}"
             echo "          Kernel: ${kernel_release}"
             echo "          Uptime: ${update_load}"
             echo "        Hostname: ${server_name}"
             echo "   Shell version: ${bash_version}"
             echo "          IPaddr: ${ipaddr}"
             info3
             echo -e "\033[36mCPU的基本信息\033[0m"
             echo "   Physical_CPUs: $Physical_CPUs"
             echo "       Virt_CPUs: $Virt_CPUs"
             echo "     CPU_Kernels: $CPU_Kernels"
             echo "        CPU_Type: $CPU_Type"
       fi;;
     'mem')
        if [ ${language} == "Chinese" ];then
             echo -e "\033[36m内存基本信息\033[0m"
             echo "            总量: ${report_MemTotal}MB"
             echo "程序认为可用内存: ${report_MemAvai}MB" 
             echo "    实际尚未使用: ${report_MemFree}MB+${report_MemAvai}MB=${report_Mem}"
             echo "      内存使用率: ${report_MemUsedPercent}"
             echo "    交换分区总量: ${report_swapTotal}"
             echo "  交换分区使用量: ${report_swapTotal}"
         
         elif [ ${language} == "English" ];then
             echo -e "\033[36m内存基本信息\033[0m"
             echo "           Total: ${report_MemTotal}MB"
             echo "           Avail: ${report_MemAvai}MB" 
             echo "            Free: ${report_MemFree}MB+${report_MemAvai}MB=${report_Mem}"
             echo "    Memory usage: ${report_MemUsedPercent}"
             echo "      Swap Total: ${report_swapTotal}"
             echo "       Swap Used: ${report_swapTotal}"
       fi;;      
  esac
      
}
################################################################################################################
info_index(){
    #加载信息
    info
    #cpu信息
    info3
    index_portal cpu
    #cpu 状态
    CPU_STATUS
    info3
    #内存信息
    index_portal mem
    info3
    #磁盘信息
    disk_info
    info3
    #网卡信息
    getnetworkstatus
}

check_rpm_iostat(){
  local rpm_name="$1"
  iostat_rpm=`rpm -qa | egrep "${rpm_name}"| wc -l`
  if [ $iostat_rpm -eq 0 ] ;then
    echo "${rpm_name} and net-tools not found,请安装后重试"
    exit 1
  fi
}
info_index

旧版本

#!/bin/bash
#所有者:北城半夏
#当前版本
#v1.0.1
#################################################################################
info3(){
 echo -e "\033[36m----------------------------------------------------------------------------------\033[0m" 
}

info(){
#系统
system=$(hostnamectl | grep System | awk '{print $3}')
kernel_release=$(hostnamectl | grep Kernel | awk -F : '{print $2}'|sed 's/^[ \t]*//g')
Virtualization=$(hostnamectl | grep Virtualization | awk '{print $2}')
server_name=$(hostname)
ipaddr=$(hostname -I)
#cpu
Physical_CPUs=$(grep "physical id" /proc/cpuinfo| sort | uniq | wc -l)
Virt_CPUs=$(grep "processor" /proc/cpuinfo | wc -l)
CPU_Kernels=$(grep "cores" /proc/cpuinfo|uniq| awk -F ': ' '{print $2}')
CPU_Type=$(grep "model name" /proc/cpuinfo | awk -F ': ' '{print $2}' | sort | uniq)
CPU_Arch=$(uname -m)
#负载
update_load=`uptime | awk -F ":" '{print $NF}'|sed 's/^[ \t]*//g'`
#bash
bash_version=`bash --version|grep "GNU bash"|awk '{print $4}'`
#内存
MemTotal=$(grep MemTotal /proc/meminfo| awk '{print $2}') #KB
MemFree=$(grep MemFree /proc/meminfo| awk '{print $2}') #KB
MemAvailable=$(grep -i Cached /proc/meminfo | awk '{print $2}' |head -1) #KB
SwapTotal=$(grep SwapTotal /proc/meminfo| awk '{print $2}')
SwapFree=$(grep SwapFree /proc/meminfo| awk '{print $2}') #KB
let MemUsed=MemTotal-MemFree
MemPercent=$(awk "BEGIN {if($MemTotal==0){printf 100}else{printf \"%.2f\",$MemUsed*100/$MemTotal}}")
report_MemTotal="$((MemTotal/1024))" #内存总容量(MB)
report_MemFree="$((MemFree/1024))" #内存剩余(MB)
report_MemAvai="$((MemAvailable/1024))" #使用中(MB)
#swap
report_swapTotal="$((SwapTotal/1024))""MB" #内存总容量(MB)
report_swapFree="$((SwapFree/1024))""MB" #内存剩余(MB)
let Memfree=MemAvailable+MemFree
let MemUsed=MemTotal-Memfree
report_Mem="$((Memfree/1024))""MB"
report_MemUsedPercent="$(awk "BEGIN {if($MemTotal==0){printf 100}else{printf \"%.2f\",$MemUsed*100/$MemTotal}}")""%" #内存使用率%


}
pd_disk_ssd(){
pd_ssd=`lsblk -d -o name|grep -v NAME`
pd_TYPE=`lsblk -d -o rota|grep -v ROTA`
for i in  ${pd_ssd};do pd_ssd_name[${#pd_ssd_name[*]}]=$i;done
for i in  ${pd_TYPE};do pd_TYPE_name[${#pd_TYPE_name[*]}]=$i;done
printf "\e[34m%-10s %-11s %-11s \e[0m\n" Disk_name Disk_Type 
local num1=$((`echo ${#pd_TYPE_name[*]}`-1))
for pd in `seq 0 ${num1}`
   do
      if [ ${pd_TYPE_name[pd]} -eq 0 ];then
          printf "\e[36m%-10s %-11s %-11s \e[0m\n" ${pd_ssd_name[pd]} SSD
      elif [ ${pd_TYPE_name[pd]} -eq 1 ];then
          printf "\e[36m%-10s %-11s %-11s \e[0m\n" ${pd_ssd_name[pd]}  HDD
      fi
done
info3
}
#网卡信息
getnetworkstatus(){
check_rpm_iostat net-tools
 local ifs=(`ifconfig | egrep "^e|^d|^l" | awk -F: '{print $1}'`)
echo -e "\033[36m网卡基本信息\033[0m" 
 local a=`ifconfig | egrep "^e|^d" |awk -F ':' '{print $1}'`
 local b=`for i in $a;  do  echo $(ifconfig ${i} |grep inet6 |awk '{print $2}') ;done`
 local ipv4=$(for i in $a;do echo "`ifconfig ${i} | awk 'NR==2{print $2}'`" ;done)
 local netmask=$(for i in $a ;do echo `ifconfig  $i|grep netmask|awk '{print $4}'` ;   done)
 local broadcast=$(for i in $a ;do echo `ifconfig  $i|grep broadcast|awk '{print $6}'` ;   done)
 local RX_packets=$(for i in $a ;do echo `ifconfig $i|grep "RX packets"|awk -F '(' '{print $2}'|cut -d ")" -f 1|awk '{print $1}'` ;   done)
 local TX_packets=$(for i in $a ;do echo `ifconfig $i|grep "TX packets"|awk -F '(' '{print $2}'|cut -d ")" -f 1|awk '{print $1}'` ;   done)
 local num=`ifconfig | egrep "^e|^d|^l" |awk -F ':' '{print $1}'|wc -l`
 local num_01=`for((i=0;i<$num;i++)); do echo $i; done`
  #ipv4
  for i in $ipv4 ;do  network_ipv4[${#network_ipv4[*]}]=$i ;done
  #ipv6
  for i in $b;  do network_ipv6[${#network_ipv6[*]}]=$i ; done
  #网卡名
  eth_name=(`ifconfig | egrep "^e|^d" | awk -F: '{print $1}'`)
  #netmask 子网掩码
  for i in $netmask;  do network_netmask[${#network_netmask[*]}]=$i ; done
  #broadcast 默认网关
  for i in $broadcast;  do network_broadcast[${#network_broadcast[*]}]=$i ; done
  #RX packets 出流量
  for i in $RX_packets;  do network_RX_packets[${#network_RX_packets[*]}]=$i ; done
  #TX packets 进流量
  for i in $TX_packets;  do network_TX_packets[${#network_TX_packets[*]}]=$i ; done

 printf "\e[34m%-13s %-15s %-15s %-15s %-10s %-15s %-23s\e[0m\n"  Network IPV4 Netmask Broadcas  RX_packets TX_packets IPV6
 for i in $num_01
  do
    printf "%-13s %-15s %-15s %-15s %-10s %-15s %-23s\n" ${eth_name[i]} ${network_ipv4[i]} ${network_netmask[i]} ${network_broadcast[i]} ${network_RX_packets[i]} ${network_TX_packets[i]} ${network_ipv6[i]}
 done

}
############################################################################################################
disk_info(){
  #磁盘
check_rpm_iostat sysstat
disk_info=`blkid|awk -F':' '{print $1}'|grep -v sr0`
for i in  ${disk_info};do disk_name[${#disk_name[*]}]=$i;done
disk_type_info=`blkid|awk  '{print $1""$NF}'|grep -v sr0|awk -F'"' '{print $2}'`
for i in  ${disk_type_info};do disk_type[${#disk_type[*]}]=$i;done
num=$((`echo ${#disk_name[*]}`-1))
for size in `seq 0 ${num}`
    do
      disk_size_array=`fdisk -l ${disk_name[size]}|grep Disk|awk '{print $3""$4}'|cut -d , -f 1`
      disk_size[${#disk_size[*]}]=$disk_size_array
      diskRead_writ_array=`iostat -d -x  ${disk_name[size]}| grep -v "^$"|tail -1|awk '{print $4"\t"$5"\t"$6}'`
      diskRead_writ[${#diskRead_writ[*]}]=${diskRead_writ_array}
done
echo -e "\033[36m磁盘基本信息\033[0m"
pd_disk_ssd
printf "\e[34m%-28s %-11s %-10s%-10s%-10s%-11s\e[0m\n" Disk_name Size  r/s     w/s    rkB/s Type
for i in `seq 0 $num`
  do
     printf "\e[32m%-28s %-10s  %-10s%-10s%-10s%-10s\e[0m\n" ${disk_name[i]} ${disk_size[i]}  ${diskRead_writ[i]} ${disk_type[i]}
  done
}

################################################################################################################
info_index(){
    info
info3
echo -e "\033[36m系统基本信息\033[0m"
echo "             OS: ${system} ${Virtualization} ${CPU_Arch}"
echo "           Host: ${system}"
echo "         Kernel: ${kernel_release}"
echo "         Uptime: ${update_load}"
echo "       Hostname: ${server_name}"
echo "  Shell version: ${bash_version}"
echo "         IPaddr: ${ipaddr}"
info3
echo -e "\033[36mCPU的基本信息\033[0m"
echo "  Physical_CPUs: $Physical_CPUs"
echo "      Virt_CPUs: $Virt_CPUs"
echo "    CPU_Kernels: $CPU_Kernels"
echo "       CPU_Type: $CPU_Type"
info3
echo -e "\033[36m内存基本信息\033[0m"
echo "          Total: ${report_MemTotal}MB"
echo "          Avail: ${report_MemAvai}MB" 
echo "           Free: ${report_MemFree}MB+${report_MemAvai}MB=${report_Mem}"
echo "   Memory usage: ${report_MemUsedPercent}"
echo "     Swap Total: ${report_swapTotal}"
echo "      Swap Used: ${report_swapTotal}"
info3
disk_info
info3
getnetworkstatus
}
check_rpm_iostat(){
  local rpm_name="$1"
  iostat_rpm=`rpm -qa | egrep "${rpm_name}"| wc -l`
  if [ $iostat_rpm -eq 0 ] ;then
    echo "${rpm_name} and net-tools not found,请安装后重试"
    exit 1
  fi
}
info_index

你可能感兴趣的:(shell脚本(整合),centos,服务器,运维)