状态转移邮件脚本
2019-05-04 本文已影响0人
Alexander_Zz
- 安装 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