• linux检测活体ip并邮件提醒


    1、安装mailx

    2、vi /etc/mail.rc,追加一下内容:

    set from=44XXX4902@qq.com
    set smtp=smtps://smtp.qq.com:465
    set smtp-auth-user=44XXX4902@qq.com
    set smtp-auth-password=lmXXXsylsppwbgcf
    set smtp-auth=login
    set ssl-verify=ignore
    set nss-config-dir=/root/.certs

    3、执行一下6句:

    mkdir -p /root/.certs/

    echo -n | openssl s_client -connect smtp.qq.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/qq.crt

    certutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crt

    certutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crt

    certutil -L -d /root/.cert

    certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ./ -i qq.crt

    4、写脚本

    #!/bin/bash
    MAIL="4450XX902@qq.com 5962XX917@qq.com"
    for ip in $(cat ip_list|sed "/^#/d") #ip_list是当前目录下IP表
    do
    ping -c 1 $ip &>/dev/null #三个ping有一个能通,说明服务器正常
    a=$?
    sleep 2
    ping -c 1 $ip &>/dev/null
    b=$?
    sleep 2
    ping -c 1 $ip &>/dev/null
    c=$?
    sleep 2
    DATE=$(date +%F" "%H:%M)
    if [ $a -ne 0 -a $b -ne 0 -a $c -ne 0 ];then
    echo -e "Date : $DATE Host : $ip Problem : Ping is failed @Mr.long." | mailx -s "Server port failed : $ip " $MAIL
    #else
    # echo "$ip ping is successful."
    fi
    done

    5、指定定时任务,参看以下两片文章

    https://www.jianshu.com/p/838db0269fd0

    https://blog.csdn.net/xiyuan1999/article/details/8160998

  • 相关阅读:
    Div+Css布局教程(-)CSS必备知识
    html表格设置
    wxAui Frame Management用法
    aui
    MySQL死锁
    InnoDB索引存储结构
    MySQL事务调优
    MySQL慢SQL语句常见诱因
    InnoDB的LRU淘汰策略
    InnoDB事务之redo log工作原理
  • 原文地址:https://www.cnblogs.com/bigdatadiary/p/12961266.html
Copyright © 2020-2023  润新知