zoukankan      html  css  js  c++  java
  • 系统安全巡检

    #!/bin/bash

    #系统信息###
    system(){
    xi=$(uname)
    echo "操作系统 $xi "
    version=`cat /etc/redhat-release`
    echo "操作系统版本 $version"
    nei=`uname -r`
    echo "操作系统内核 $nei"
    time=`who -r`
    echo "服务器当前运行时间 $time"
    chong=`last reboot`
    echo "服务器最后重启时间 $chong"
    name=`hostname`
    echo "服务器名称 $name"
    }
    #######网络信息#######
    network(){
    a=`ifconfig ens33 |awk '/netmas/{print $2}'`
    echo "ip= $a"
    ping -c 3 www.baidu.com >/dev/null
    if [ $? -eq 0 ]; then
    echo "服务器的网络是ok的"
    else
    echo "check 检查服务器"
    fi
    }
    ####硬件信息######
    cpu(){
    ###cpu###
    cpu_shu=`cat /proc/cpuinfo |grep "physical id" |wc -l`
    echo "cpu个数 $cpu_shu"
    cpu_he=`cat /proc/cpuinfo |grep "cores" |uniq |awk '{print $4}'`
    echo "cpu核心数 $cpu_he"
    cpu_xing=`cat /proc/cpuinfo |grep "model name" |awk -F: '{print $2}'`
    echo "cpu型号 $cpu_xing"

    }
    #####内存######
    mem(){
    nei_total=`free -m |awk '/Mem/{print $2}'`
    echo "内存总量 $nei_total"
    nei_free=`free -m |awk '/Mem/{print $4}'`
    echo "剩余内存容量 $nei_free"
    }

    ###磁盘###
    disk(){
    ###方法一###
    sum=0
    a=($(df -T |awk '{print $3}' |grep -v "1K"))
    for i in ${a[@]}
    do
    let sum=sum+$i

    done
    let sumg=sum/1024/1024
    echo "磁盘总量${sumg}G"
    ###方法二###
    total=`lsblk |awk '/disk/{print $4}'`
    echo "磁盘总量$total"
    ###剩余磁盘总量###
    sum=0
    a=($(df -T |awk '{print $5}' |sed "1d"))
    for i in ${a[@]}
    do
    let sum=sum+$i

    done
    let sumg=sum/1024/1024
    echo "磁盘剩余总量${sumg}G"
    }

    #################安全信息###############
    an(){
    ####统计登录####
    count_user=`last |grep "still logged in"|awk '{print $1}' |uniq`
    echo "登录用户信息 $count_user"
    ###md5校验###
    [ -f /opt/pwd ] || md5sum /etc/passwd > /opt/pwd
    md5sum -c /opt/pwd --quiet
    if [ $? -eq 0 ]; then
    echo "file is ok"
    else
    echo "文件被篡改"
    fi
    }

    system
    network
    cpu
    mem
    disk
    an

  • 相关阅读:
    ios专题 - CocoaPods - 初次体验
    ios专题 - CocoaPods - 安装
    Objective-C浅拷贝和深拷贝
    支付宝交互流程
    UITabBar的隐藏
    iOS-容易造成循环引用的三种场景
    FMDB 的基本操作
    Swap file ".Podfile.swp" already exists!
    将UIImage保存成JPG或PNG格式存储在本地
    UI常用控件的一些属性
  • 原文地址:https://www.cnblogs.com/fatzi/p/12918054.html
Copyright © 2011-2022 走看看