状态转移邮件脚本

2019-05-04  本文已影响0人  Alexander_Zz

~]# 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

上一篇下一篇

猜你喜欢

热点阅读