zoukankan      html  css  js  c++  java
  • linux 监控服务器脚本

    #!/bin/bash

    ctime=`date +%x%T`
    monitor_dir=/home/jk/
    if [ ! -d $monitor_dir ]; then
        mkdir $monitor_dir
    fi
    cd $monitor_dir
    web_stat_log=web.status
    if [ ! -f $web_stat_log ]; then
       touch $web_stat_log
    fi
    server_list_file=server.list
    if [ ! -f $server_list_file ]; then
       echo "`date '+%Y-%m-%d %H:%M:%S'` ERROR:$server_list_file NOT exists!" >>$web_stat_log
    exit 1
    fi

    for website in `cat $server_list_file`
    do
       url="http://$website/index.html"
       server_status_code=`curl -o /dev/null -s -m 10 --connect-timeout 10 -w %{http_code} "$url"`
       if [ "$server_status_code" = "200" ]; then
            echo "`date '+%Y-%m-%d %H:%M:%S'` visit $website status code 200 OK" >>$web_stat_log
       else
            echo "`date '+%Y-%m-%d %H:%M:%S'` visit $website $server_status_code error!!! server can't connect at 10s or stop response at 10 s, send alerm sms ..." >>$web_stat_log
            echo "$website 已经10秒打不开了!#$server_status_code#"  | mail -s $ctime  ***@139.com
       fi
    done
    exit 0

  • 相关阅读:
    cppPrimer学习18th
    cppPrimer学习17th
    cppPrimer学习15th
    常用网站记录
    cppPrimer学习16th
    关于nfs内网穿透frp/nps的问题记录
    unp[unix 网络环境编程]学习 vscode环境搭建
    cppPrimer学习14th
    cppPrimer学习14th
    cppPrimer学习13th
  • 原文地址:https://www.cnblogs.com/rongkang/p/4418780.html
Copyright © 2011-2022 走看看