#!/bin/sh
# @(#)UNIX_notifier.sh 1.0
#         Copyright 2000, American Power Conversion, Inc.
#
# NAME: notifier.sh
#
# REV: 1.0
#
# LAST MODIFIED: 10/20/2000
#
# DESCRIPTION: Will send the message to the users specified.
# The parameters passed include -
#     USER: single user to receive messages
#     MSG:  message to be sent
#     SENDTOTAL: ALL (send to all users)
#                SPECIFIC - send to USER

 PATH=/bin:/sbin:/usr/bin:/usr/sbin:/etc:/usr/ccs/bin
 export path

# Send the message to a single user
SendSingle() {
USER=`echo $USER | sed s/\"//g`
echo $MSG | write $USER 
}
# Send the message to all users
SendAll() {
 echo $MSG | wall 2>/dev/null
}

SOURCE=$2
SPACE=" "
# Add all words of a multi-word message together

while [ $1 != \"PowerChute\" ]
do
 MSG=`echo $MSG$SPACE$1`
 shift
done
 shift


#Decide if message is to ALL users or to a specific user

if [ $1 = SPECIFIC ]
then 
 #send message to specific users only
 shift
 until [ -z $1 ]
 do
  USER=$1
  SendSingle
  shift
 done
else
# send message to all users

SendAll
fi

# Cleanup

rm -f $MSG
rm -f $USER
rm -f $SPACE


