查看主机配置,ip的一个小脚本

  • A+
所属分类:shell
#!/bin/bash
# -*- coding: utf-8 -*-
#检测系统版本和配置

readsysver()
{
#系统版本信息
OS=`cat /etc/redhat-release`
printf "\033[32m 操作系统版本:%s %s\n\033[0m" "$OS"
}


readsysinfo()
{

#主机型号
if [ -e /usr/sbin/dmidecode ]
then
  sysnum=`dmidecode -s system-product-name`
else
  `yum -y install dmidecode 2>&1 /dev/null`
fi
#获取服务器配置
#CPU核数
ker=`lscpu |grep "^CPU(s)"|awk '{print $2}'`

#cpu型号
cpuxinhao=`lscpu|grep "Model name"|awk '{$1="";$2="";print $0}'`

#内存cat /proc/meminfo |grep "MemTotal"|awk '{$1="";print $0}'
memo=`cat /proc/meminfo |grep "MemTotal"|cut -d" "  -f 9`

#网卡
ipinfo=`ip addr|grep "eth0" -A1|grep "inet"|cut -d" " -f 6`
#内网
nipinfo=`ip addr|grep "eth1" -A1|grep "inet"|cut -d" " -f 6`

printf  "\033[32m %-10s \033[0m" "主机品牌:"
printf  "\033[32m %-10s\n \033[0m" "$sysnum"
printf  "\033[32m cpu:%-10s\n \033[0m" "$cpuxinhao" 
printf "\033[32m %-5s \033[0m" "CPU:"
printf  "\033[32m %10s\n \033[0m" "$ker"
printf  "\033[32m 内存:%-10s\n \033[0m" "$memo"
printf "\033[32m 公网:%-10s\n \033[0m" "$ipinfo"
printf "\033[32m 内网:%-10s\n \033[0m" "$nipinfo"
}

diskinfo()
{
  #磁盘信息
  disk=`df -h|grep "^/dev"`
  printf "\033[33m %s\t %s\t %s\t %s\t %s\t %s 分区名 大小 使用 可用 使用率 挂载点\n \033[0m"
  printf "%s\n" "$disk"
}

speedlist()
{
  local speed_result
  if [ ! -f /usr/bin/pip ]
    then
      pip install speedtest-cli
      echo "速度测试中..."
      speedtest-cli --share >/tmp/speed.tmp
      speed_result=`grep "Share results:" /tmp/speed.tmp |cut -d" " -f3`
  else
    echo "速度测试中..."
    speedtest-cli --share >/tmp/speed.tmp
    speed_result=`grep "Share results:" /tmp/speed.tmp |cut -d" " -f3`
  fi
  
  echo $speed_result
}
main()
{
  readsysver
  readsysinfo
  diskinfo
  speedlist
}

main

 

  • 我的微信
  • 这是我的微信扫一扫
  • weinxin
  • 我的微信公众号
  • 我的微信公众号扫一扫
  • weinxin

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: