首页
登录 | 注册

主机巡检脚本:OSWatcher.sh

主机巡检脚本:OSWatcher.sh

2016-09-26更新,目前该脚本只支持Linux操作系统,后续有需求可以继续完善。

注意:

经测试,普通用户执行脚本可以顺利执行前9项检查;

第10项,普通用户检查/var/log/messages很可能没有读权限,如有需要巡检此系统日志,建议切换root用户执行此脚本

#!/bin/bash
echo ""
echo "OSWatcher Version:2.0.0"
echo ""
#Create Time:2016-04-08  
#Update Time:2016-09-26
######################################################################
#设置命令的路径,防止命令找不到路径
PATH=$PATH:/usr/sbin/
export PATH
echo "the PATH is:$PATH"
######################################################################
PLATFORM=`/bin/uname`
#
######################################################################
# Create log subdirectories if they don't exist
######################################################################
if [ ! -d archive ]; then
        mkdir archive
fi        

case $PLATFORM in
  Linux)
    DF='df -h'
    MEMINFO='free -m'
    MPSTAT='mpstat 1 3'
    TOP='eval top -b -n 1 | head -50'
    VMSTAT='vmstat 1 3'
    IOSTAT='iostat -d -x -k 1 5'
    PSELF='ps -elf'
    BOOTLOG='tail -500 /var/log/boot.log'
    SYSLOG='dmesg'
    MESSAGE='tail -500 /var/log/messages'
    ;;
esac
hostn=`hostname`
hour=`date +'%m.%d.%y.%H00.dat'`
echo "`date` Collect">archive/${hostn}_$hour
######################################################################
# Test for discovery of os utilities. Notify if not found.
######################################################################
echo ""
echo "Starting Data Collection..."
echo ""

case $PLATFORM in
  Linux)
    $DF > /dev/null 2>&1
    if [ $? = 0 ]; then
      echo "DF found on your system."
            echo "--1.DF==========================">>archive/${hostn}_$hour
            $DF>>archive/${hostn}_$hour
      MEMFOUND=1
    else
      echo "Warning... DF not found on your system."
      MEMFOUND=0
    fi
    
    $MEMINFO > /dev/null 2>&1
    if [ $? = 0 ]; then
      echo "meminfo found on your system."
            echo "--2.MEMINFO==========================">>archive/${hostn}_$hour
            $MEMINFO>>archive/${hostn}_$hour
      MEMFOUND=1
    else
      echo "Warning... /proc/meminfo not found on your system."
      MEMFOUND=0
    fi
    
    $MPSTAT > /dev/null 2>&1
    if [ $? = 0 ]; then
      echo "MPSTAT found on your system."
            echo "--3.MPSTAT==========================">>archive/${hostn}_$hour
          $MPSTAT>>archive/${hostn}_$hour
      MEMFOUND=1
    else
      echo "Warning... MPSTAT not found on your system."
      MEMFOUND=0
    fi
    
    $TOP > /dev/null 2>&1
    if [ $? = 0 ]; then
      echo "TOP found on your system."
            echo "--4.TOP==========================">>archive/${hostn}_$hour
          $TOP>>archive/${hostn}_$hour
      MEMFOUND=1
    else
      echo "Warning... TOP not found on your system."
      MEMFOUND=0
    fi
    
    $VMSTAT > /dev/null 2>&1
    if [ $? = 0 ]; then
      echo "VMSTAT found on your system."
            echo "--5.VMSTAT==========================">>archive/${hostn}_$hour
          $VMSTAT>>archive/${hostn}_$hour
      MEMFOUND=1
    else
      echo "Warning... VMSTAT not found on your system."
      MEMFOUND=0
    fi
    
    $IOSTAT > /dev/null 2>&1
    if [ $? = 0 ]; then
      echo "IOSTAT found on your system."
            echo "--6.IOSTAT==========================">>archive/${hostn}_$hour
          $IOSTAT>>archive/${hostn}_$hour
      MEMFOUND=1
    else
      echo "Warning... IOSTAT not found on your system."
      MEMFOUND=0
    fi
    
    $PSELF > /dev/null 2>&1
    if [ $? = 0 ]; then
      echo "PSELF found on your system."
            echo "--7.PSELF==========================">>archive/${hostn}_$hour
          $PSELF>>archive/${hostn}_$hour
      MEMFOUND=1
    else
      echo "Warning... PSELF not found on your system."
      MEMFOUND=0
    fi
    
    $BOOTLOG > /dev/null 2>&1
    if [ $? = 0 ]; then
      echo "BOOTLOG found on your system."
            echo "--8.BOOTLOG==========================">>archive/${hostn}_$hour
          $BOOTLOG>>archive/${hostn}_$hour
      MEMFOUND=1
    else
      echo "Warning... BOOTLOG not found on your system."
      MEMFOUND=0
    fi
    
    $SYSLOG > /dev/null 2>&1
    if [ $? = 0 ]; then
      echo "SYSLOG found on your system."
            echo "--9.SYSLOG==========================">>archive/${hostn}_$hour
          $SYSLOG>>archive/${hostn}_$hour
      MEMFOUND=1
    else
      echo "Warning... SYSLOG not found on your system."
      MEMFOUND=0
    fi
    
    $MESSAGE > /dev/null 2>&1
    if [ $? = 0 ]; then
      echo "MESSAGE found on your system."
            echo "--10.MESSAGE==========================">>archive/${hostn}_$hour
          $MESSAGE>>archive/${hostn}_$hour
      MEMFOUND=1
    else
      echo "Warning... MESSAGE not found on your system."
      MEMFOUND=0
    fi
    
    ;;
esac 

echo ""
echo "Discovery completed."
echo "Collection completed."
echo "The Collected result saved in ./archive/${hostn}_$hour."
echo ""

 


相关文章

  • jenkins定位GitLab推送的最新Webhook中push event来自哪一个分支
    转载请标明出处:http://www.cnblogs.com/zblade/ 一.调研目的 jenkins可以和GitLab搭档,每当GitLab上有commit的时候,都可以触发jenkins执行相关的操作,具体的实现,可以参看我前面的博 ...
  • 补习系列(20)-大话 WebSocket 与 "尬聊"的实现
    目录 一.聊聊 WebSocket 二.Stomp 是个什么鬼 三.SpringBoot 整合 WebSocket A. 引入依赖 B. WebSocket 配置 C. 控制器 D. 前端实现 四.参考文档 一.聊聊 WebSocket 从 ...
  • 系统掉盘,机械硬盘掉盘,固态掉盘
    之前的立式服务器当了主机打起了游戏,但是经过半年的游戏的时间发现,机子开始变得卡了?我不由得怀疑是不是机子出现老化的问题了.打开盖子一看进了灰尘,就开始清灰了,但是情况在心理暗示的情况下没有好转.这时我打游戏才了打了三个月. 不由得开始思考 ...
  • 学了很多乱七杂八的东西,但是依然停留在前端,在工作中一直和后端交流,但是不太了解数据库是怎么回事,为了加强学习,准备学习一些关于数据库相关的东西. 说起数据库可能会有很多很多,SQLServer.Oracle.Sybase等等等,还有就是要 ...
  • 1.什么是跨越? 一个网页向另一个不同域名/不同协议/不同端口的网页请求资源,这就是跨域. 跨域原因产生:在当前域名请求网站中,默认不允许通过ajax请求发送其他域名. 2.为什么会产生跨域请求? 因为浏览器使用了同源策略 3.什么是同源策 ...
  • MongoDB【快速入门】
    1.MongDB 简介 MongoDB(来自于英文单词"Humongous",中文含义为"庞大")是可以应用于各种规模的企业.各个行业以及各类应用程序的开源数据库.作为一个适用于敏捷开发的数据库,Mo ...

2019 cecdns.com webmaster#cecdns.com
12 q. 0.078 s.
京ICP备10005923号