• 虚拟机信息巡检脚本


    方便快速巡检虚拟机的资源和信息,编写的巡检脚本

    效果如下:

    样本:

     

    1. #!/bin/sh"
    2. echo "#######################################「OS系统信息」##########################################"
    3. OS_TYPE=`uname`
    4. OS_Number=`dmidecode -t system |grep 'Serial Number'|awk '{print $3}'|awk -F, '{print $1}'`
    5. OS_VERSION=`cat /etc/redhat-release`
    6. OS_IPADDR=`ifconfig ens192|grep "inet" |awk '{print $2}' | sed -n '1p'`
    7. OS_KERNER=`uname -a|awk '{print $3}'`
    8. OS_NOWTIME=`date +%F_%T`
    9. OS_RUN_TIME=`uptime |awk '{print $3,$4}'|awk -F, '{print $1}'`
    10. OS_LASTREBOOT_TIME=`who -b|awk '{print $2,$3}'`
    11. OS_HOSTNAME=`hostname`
    12. echo " 主机类型: $OS_TYPE"
    13. echo " 主机序列号: $OS_Number"
    14. echo " 系统版本: $OS_VERSION"
    15. echo " 系统IP地址: $OS_IPADDR"
    16. echo " 内核版本: $OS_KERNER"
    17. echo " 系统时间: $OS_NOWTIME"
    18. echo " 运行时间: $OS_RUN_TIME"
    19. echo " 最后重启时间: $OS_LASTREBOOT_TIME"
    20. echo " 主机名称: $OS_HOSTNAME"
    21. echo " SELinux:` /usr/sbin/sestatus | grep 'SELinux status:' | awk '{print $3}'`"
    22. echo " 语言环境:`echo $LANG`"
    23. echo "#######################################「OS资源信息」##########################################"
    24. OS_CPU_PRO=`cat /proc/cpuinfo |grep "processor" | wc -l`
    25. OS_CPU_COR=`cat /proc/cpuinfo| grep "cpu cores"| uniq |awk {'print $4'}`
    26. OS_CPU_TYPE=`grep "model name" /proc/cpuinfo | awk -F ': ' '{print $2}' | sort | uniq`
    27. echo " CPU总个数: $OS_CPU_PRO"
    28. echo " CPU总核数: $OS_CPU_COR"
    29. echo " CPU型 号: $OS_CPU_TYPE"
    30. OS_SWAP_S=`free|grep Swap|awk {'print $2'}`
    31. OS_PARTS=(`df -T|sed 1d|egrep -v "tmpfs|sr0"|awk {'print $3'}`)
    32. OS_MEM_TAL=`free -m|grep Mem|awk '{print $2}'`
    33. OS_MEM_FREE=`free -m|grep Mem|awk '{print $7}'`
    34. echo " 内存总量: ${OS_MEM_TAL}MB"
    35. echo " 内存余量: ${OS_MEM_FREE}MB"
    36. OS_DISKS=0
    37. OS_SWAP=`free|grep Swap|awk {'print $2'}`
    38. OS_PARTS=(`df -T|sed 1d|egrep -v "tmpfs|sr0"|awk {'print $3'}`)
    39. for ((i=0;i<`echo ${#OS_PARTS[*]}`;i++))
    40. do
    41. OS_DISKS=`expr $OS_DISKS + ${OS_PARTS[$i]}`
    42. done
    43. ((OS_DISKS=\($OS_DISKS+$OS_SWAP\)/1024/1024))
    44. echo " 磁盘总量: ${OS_DISKS}GB"
    45. OS_DISKS=0
    46. OS_SWAP=`free|grep Swap|awk '{print $4}'`
    47. OS_PARTS=(`df -T|sed 1d|egrep -v "tmpfs|sr0"|awk '{print $5}'`)
    48. for ((i=0;i<`echo ${#OS_PARTS[*]}`;i++))
    49. do
    50. OS_DISKS=`expr $OS_DISKS + ${OS_PARTS[$i]}`
    51. done
    52. ((freetotal=\($OS_DISKS+$OS_SWAP\)/1024/1024))
    53. echo " 磁盘余量: ${freetotal}GB"
    54. echo "#######################################「OS网络监测」##########################################"
    55. echo `ip a | grep eno | awk "NR==2" | awk '{print $NF,":",$2}'`
    56. echo "网关:`ip route | awk 'NR==1'| awk '{print $3}'`"
    57. echo "DNS: `cat /etc/resolv.conf | grep "nameserver" | awk '{print $2}'`"
    58. ping -c 4 www.baidu.com > /dev/null
    59. if [ $? -eq 0 ];then
    60. echo "网络连接状态:正常"
    61. else
    62. echo "网络连接状态:失败"
    63. fi
    64. echo
    65. echo "#######################################「OS安全检查」##########################################"
    66. echo "用户登陆信息:`last | grep "still logged in" | awk '{print $1}'| sort | uniq`"
    67. md5sum -c --quiet /etc/passwd > /dev/null 2&>1
    68. if [ $? -eq 0 ];then
    69. echo "文件未被篡改"
    70. else
    71. echo "文件被篡改"
    72. fi

  • 相关阅读:
    Ubuntu上安装Chrome浏览器
    Wolfram语言之父:ChatGPT到底能做什么? | 阿Q送书第六期
    Linux编译器gcc的使用
    MapReduce极简实现
    Java 某个经纬度是否在genjson文件中
    react-生命周期与组件传参
    5G商企专网,助力打造城市生命线“安徽样板”
    【每日一题Day47】LC1774最接近目标价格的甜点成本 | 回溯 哈希表
    HMTL知识点系列(1)
    Midjourney绘画提示词Prompt参考学习教程
  • 原文地址:https://blog.csdn.net/xianjie0318/article/details/133133250