1#!/bin/sh
2
3# Licensed to the Apache Software Foundation (ASF) under one
4# or more contributor license agreements.  See the NOTICE file
5# distributed with this work for additional information
6# regarding copyright ownership.  The ASF licenses this file
7# to you under the Apache License, Version 2.0 (the
8# "License"); you may not use this file except in compliance
9# with the License.  You may obtain a copy of the License at
10#
11#      http://www.apache.org/licenses/LICENSE-2.0
12#
13# Unless required by applicable law or agreed to in writing, software
14# distributed under the License is distributed on an "AS IS" BASIS,
15# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16# See the License for the specific language governing permissions and
17# limitations under the License.
18
19#
20#   Example alarm bin program. Proxy manager execs this script with
21# a brief message as its argument. This program sends mail to the
22# e-mail address passed in by the caller.  The subject of the
23# e-mail is the passed in message, and a 'date' stamp is added
24# as the body.
25#
26ostype=`(uname -s) 2>/dev/null`
27if [ "$ostype" = "Linux" ]; then
28SENDMAIL="/usr/sbin/sendmail"
29else
30  SENDMAIL="/usr/lib/sendmail"
31fi
32
33if [ ! -x $SENDMAIL ]; then
34    echo "$0: Could not find $SENDMAIL program"
35    exit 1
36fi
37
38if [ $# -eq 1 ]; then
39  # if only one parameter, then no email information was provided
40  msg="`hostname` $1"
41  echo
42  echo "[example_alarm_bin.sh] no e-mail sent: $msg"
43  echo
44  exit 0
45
46elif [ $# -eq 4 ]; then
47  # if four parameters, the caller specified email information
48  msg="`hostname` $1"
49  email_from_name=$2
50  email_from_addr=$3
51  email_to_addr=$4
52
53  result=`(echo "From: $email_from_name <$email_from_addr>"; echo "To: $email_to_addr"; echo "Subject: $msg"; echo; date) | $SENDMAIL -bm $email_to_addr`
54  if [ "$result" = "" ]; then
55    echo
56    echo "[example_alarm_bin.sh] sent alarm: $msg";
57    echo
58    exit 0
59  else
60    echo
61    echo "[example_alarm_bin.sh] sendmail failed"
62    echo
63    exit 1
64  fi
65
66else
67  # give a little help
68  echo "Usage: example_alarm_bin.sh <message> [<email_from_name> <email_from_addr> <email_to_addr>]"
69  exit
70
71fi
72