这个脚本适用于统计系统信息的

适用版本:Centos6、Centos7

  1. #!/bin/bash
  2. #
  3. #********************************************************************
  4. #encoding -*-utf8-*-
  5. #Author: zhangshang
  6. #Date: 2017-11-25
  7. #URL: http://blog.vservices.top/myblog
  8. #Description: 显示当前主机系统信息
  9. #Copyright (C): 2017 All rights reserved
  10. #QQ Numbers: 765030447
  11. #********************************************************************
  12. echo -e "\033[31m**********************System info**************************\033[0m"
  13. #主机名
  14. echo -e "\033[33mHostname:\033[0m\033[32m`hostname`\033[0m"
  15. #网卡IP
  16. echo -e "\033[33mIPV4 Address\033[0m"
  17. #取出网卡名
  18. for i in `ifconfig | tr -s '[:blank:]' | grep ^[[:alnum:]] | cut -d: -f1`
  19. do
  20. ipaddr=`ifconfig | grep -A 1 $i | grep inet | grep netmask | awk '{print $2}'`
  21. echo -e "\t$i:\t\033[32m$ipaddr\033[0m"
  22. done
  23. unset i
  24. #系统版本
  25. echo -e "\033[33mSystem_version:\t\033[0m\033[32mCentos `cat /etc/centos-release | grep -o "[[:digit:]]\+\.[[:digit:]]\+"`\033[0m"
  26. #内核版本
  27. echo -e "\033[33mKernel_version:\t\033[0m\033[32m`uname -r`\033[0m"
  28. #CPU型号
  29. echo -e "\033[33mCPU Model:\t\033[0m \033[32m`cat /proc/cpuinfo | grep name | cut -d: -f2`\033[0m"
  30. #内存信息
  31. echo -e "\033[33mMemery_Size\t\033[0m"
  32. (( mem_total=`cat /proc/meminfo | grep MemTotal | awk '{print $2}'` / 1024 ))
  33. (( mem_free=`cat /proc/meminfo | grep MemFree | awk '{print $2}'`/ 1024 ))
  34. (( swap_total=`cat /proc/meminfo | grep SwapTotal | awk '{print $2}'` / 1024 ))
  35. (( swap_free=`cat /proc/meminfo | grep SwapFree | awk '{print $2}'` / 1024 ))
  36. echo -e "\tTotal_mem:\t\033[32m$mem_total MB\033[0m"
  37. echo -e "\tFree_mem:\t\033[32m$mem_free MB\033[0m"
  38. echo -e "\tTotal_swap:\t\033[32m$swap_total MB\033[0m"
  39. echo -e "\tFree_swap:\t\033[32m$swap_free MB\033[0m"
  40. unset mem_total mem_free swap_total swap_free
  41. #硬盘信息
  42. echo -e "\033[33mHarddisk_info\033[0m"
  43. #根分区信息
  44. rootinfo=`df -B g | grep "/$" | awk '{print "\ttotal_size:",$2,"\t\tused_ratio:",$5}'`
  45. rootinode=`df -i -h| grep "/$" | awk '{print "\ttotal_inodes:",$2,"\t\tused_inodes_ratio:",$5}'`
  46. echo -e "\t\\ \033[32m\t$rootinfo\033[0m"
  47. echo -e "\t\033[32m\t$rootinode\033[0m"
  48. #其他分区信息
  49. for i in `df -B G | grep /dev/sd | grep -v "/$" | awk '{print $1}'`
  50. do
  51. echo -e "\t$i\033[32m`df -B G | grep $i | awk '{print "\ttotal_size:",$2,"\t\t\tused_ratio:",$5}'`\033[0m"
  52. echo -e "\t\033[32m\t`df -i -h | grep $i | awk '{print "\ttotal_inodes:",$2,"\t\tused_inodes_ratio:",$5}'`\033[0m"
  53. done
  54. unset rootinfo rootinode i

结果

  1. **********************System info**************************
  2. Hostname:joker-7-01
  3. IPV4 Address
  4. ens33: 192.168.253.129
  5. lo: 127.0.0.1
  6. System_version: Centos 7.4
  7. Kernel_version: 3.10.0-693.el7.x86_64
  8. CPU Model: Intel(R) Core(TM) i7-7500U CPU @ 2.70GHz
  9. Memery_Size
  10. Total_mem: 976 MB
  11. Free_mem: 554 MB
  12. Total_swap: 2047 MB
  13. Free_swap: 2047 MB
  14. Harddisk_info
  15. \ total_size: 50G used_ratio: 9%
  16. total_inodes: 25M used_inodes_ratio: 1%
  17. /dev/sda1 total_size: 1G used_ratio: 16%
  18. total_inodes: 512K used_inodes_ratio: 1%
文档更新时间: 2018-12-12 20:52   作者:张尚