状态转移邮件脚本

  • 安装 mailx 包
~]# yum install -y mailx
~]# echo "text" | mail -s "testsubject" alexander_zz@yeah.net
  • 脚本配置
~]# vim /etc/keepalived/notify.sh

#!/bin/bash
#
contact='alexander_zz@yeah.net

notify() {
    mailsubject="$(hostname) became $1, VIP moved"
    mailbody="$(date +'%F %T'): vrrp transition, $(hostname) became $1"
    echo "$mailbody" | mail -s "$mailsubject" $contact
}

case $1 in
    master)
        notify master
        ;;
    backup)
        notify backup
        ;;
    fault)
        notify fault 
        ;;
    *)
        echo "Usage: $(basename $0) {master|backup|fault}"
        exit 1
        ;;
esac

  • 调用方法
    notify_master “/etc/keepalived/notify.sh master”
    notify_backup “/etc/keepalived/notify.sh backup”
    notify_fault “/etc/keepalived/notify.sh fault”

    《状态转移邮件脚本》 image.png

    原文作者:Alexander_Zz
    原文地址: https://www.jianshu.com/p/06c63226ab5d
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞