zoukankan      html  css  js  c++  java
  • Linux 系统健康巡检脚本

    客户应用系统服务器要做健康检查,操作系统为Red Hat Enterprise Linux 5.6,数据库为oracle 10g,写了如下shell脚本:
    #!/bin/bash
    echo "You are logged in as `whoami`";
    if [ `whoami` != root ]; then
    echo "Must be logged on as root to run this script."
    exit
    fi
    CHECK_DATE=`date +%F`
    echo "Running script. at `date`"
    CHECK_REPORT_PATH=/tmp/getinfo
    ls -d $CHECK_REPORT_PATH
    if [ $? -gt 0 ]
    then
    mkdir $CHECK_REPORT_PATH
    fi
    chmod -R 777 $CHECK_REPORT_PATH
    CURRENT_DIR=`pwd`
    echo "#################### Check Start ####################"
    HOST=`hostname`
    echo "********Hostname Check**********" >$CHECK_REPORT_PATH/Report_$CHECK_DATE
    echo "Hostname is $HOSTNAME" >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
    echo -e "----------------------------------------------------
    ">>$CHECK_REPORT_PATH/Report_$CHECK_DATE
    #系统版本检查
    echo "********OS Level**********" >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
    uname -a >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
    echo -e "----------------------------------------------------
    ">>$CHECK_REPORT_PATH/Report_$CHECK_DATE
    #系统日志检查
    echo "********System log*******" >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
    cat /var/log/messages >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
    echo -e "----------------------------------------------------
    ">>$CHECK_REPORT_PATH/Report_$CHECK_DATE
    #文件系统检查
    echo "********File System**********" >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
    df -h >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
    echo "over 75%" >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
    echo -e "----------------------------------------------------
    ">>$CHECK_REPORT_PATH/Report_$CHECK_DATE
    df -h |grep '[7-9][5-9]%'>>$CHECK_REPORT_PATH/Report_$CHECK_DATE
    #网络地址配置信息
    echo "********System /etc/hosts********" >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
    cat /etc/hosts >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
    echo -e "----------------------------------------------------
    ">>$CHECK_REPORT_PATH/Report_$CHECK_DATE
    #查看内存使用情况
    echo "**********mem check************" >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
    free >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
    echo -e "----------------------------------------------------
    ">>$CHECK_REPORT_PATH/Report_$CHECK_DATE
    vmstat >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
    echo -e "----------------------------------------------------
    ">>$CHECK_REPORT_PATH/Report_$CHECK_DATE
    #查看磁盘读写情况
    echo "********io check**********" >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
    iostat >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
    echo -e "----------------------------------------------------
    ">>$CHECK_REPORT_PATH/Report_$CHECK_DATE
    #网络检查
    echo "********network route check**********" >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
    netstat -rn >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
    echo "********network check**********" >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
    ifconfig -a >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
    echo -e "----------------------------------------------------
    ">>$CHECK_REPORT_PATH/Report_$CHECK_DATE
    #环境变量检查
    echo "********env info****************" >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
    env >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
    echo -e "----------------------------------------------------
    ">>$CHECK_REPORT_PATH/Report_$CHECK_DATE
    #用户组检查
    echo "********group info****************" >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
    cat /etc/group >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
    echo -e "----------------------------------------------------
    ">>$CHECK_REPORT_PATH/Report_$CHECK_DATE
    #用户密码检查
    echo "********user info****************" >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
    cat /etc/passwd >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
    echo -e "----------------------------------------------------
    ">>$CHECK_REPORT_PATH/Report_$CHECK_DATE
    #检查操作系统kernel信息
    echo "********System kernel info****************" >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
    su - root -c $CURRENT_DIR/check_kernel.sh >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
    echo -e "----------------------------------------------------
    ">>$CHECK_REPORT_PATH/Report_$CHECK_DATE
    #检查操作系统定时任务
    echo "********System crontab info****************" >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
    crontab -l >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
    echo -e "----------------------------------------------------
    ">>$CHECK_REPORT_PATH/Report_$CHECK_DATE
    #检查系统裸设备属主
    echo "******** RAW****************" >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
    ls -l /dev/sd* >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
    echo -e "----------------------------------------------------
    ">>$CHECK_REPORT_PATH/Report_$CHECK_DATE
    #检查服务器上运行的数据库信息
    echo "********get oracle info****************" >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
    Instance=`ps -ef|grep -v grep|grep oracle|awk '{print $1}'`
    for i in ${Instance}
    do
    su - $i -c $CHECK_REPORT_PATH/getdbinfo.sh
    done
    echo -e "----------------------------------------------------
    ">>$CHECK_REPORT_PATH/Report_$CHECK_DATE
    echo "#################### Check End! ####################"
  • 相关阅读:
    sql server 删除重复数据新思路
    sqlserver 迁移 mysql
    ASP.NET Web deployment task failed. 请与服务器管理员联系,检查授权和委派设置 部署任务失败的解决方案
    数据库交互之减少IO次数
    sqlserver 安全设置
    windows设置相对路径的快捷方式
    利用SignalR实现实时推送信息
    image magick 备忘
    dotnetCore开发中遇到的一些问题
    “NETSDK1061: 项目是使用 Microsoft.NETCore.App 版本 2.1.14 还原的, 但使用当前设置, 将改用版本 2.1.0。”的处理方法
  • 原文地址:https://www.cnblogs.com/lkj371/p/12761012.html
Copyright © 2011-2022 走看看