#!/bin/sh # # Resource script for MailTo # # Author: Alan Robertson <alanr@unix.sh> # # Description: sends email to a sysadmin whenever a takeover occurs. # # Note: This command requires an argument, unlike normal init scripts. # # This can be given in the haresources file as: # # You can also give a mail subject line or even multiple addresses # MailTo::alanr@unix.sh::BigImportantWebServer # MailTo::alanr@unix.sh,spoppi@gmx.de::BigImportantWebServer # # This will then be put into the message subject and body. # # License: GPL ARGS="$0 $*" # Source function library. prefix=/usr exec_prefix=/usr . /etc/ha.d/shellfuncs us=`uname -n` usage() { echo "Usage: $0 <email> [subject] {start|stop|status}" echo "$Id: MailTo.in,v 1.5.4.2 2004/04/29 01:09:37 alan Exp $" exit 1 } MailProgram() { /bin/mail -s "$1" "$email" <<EOF $Subject Command line was: $ARGS EOF } SubjectLine() { case $1 in ??*) echo $1;; *) echo "Resource Group";; esac } MailToStart() { Subject="`SubjectLine $subject` Takeover in progress on $us" MailProgram "$Subject" $1 } MailToStop () { Subject="`SubjectLine $subject` Migrating resource away from $us" MailProgram "$Subject" $1 } # # See how we were called. # # The order in which heartbeat provides arguments to resource # scripts is broken. It should be fixed. # case "$#" in 0|1) echo "At least 1 Email address has to be given!" usage ;; 2) email=$1 cmd=$2 subject="" ;; 3) email=$1 cmd=$3 subject=$2 ;; *) echo "Additional parameters found: $# but max. 3 are allowed!" usage;; esac case "$cmd" in start) MailToStart ;; stop) MailToStop ;; # Not quite sure what to do with this one... # We aren't a continuously running service - so it's not clear # status) echo "stopped" ;; *) usage ;; esac exit 0