1 #******************************************************************************* 2 # Copyright (c) 2005, 2006 IBM Corporation and others. 3 # All rights reserved. This program and the accompanying materials 4 # are made available under the terms of the Eclipse Public License v1.0 5 # which accompanies this distribution, and is available at 6 # http://www.eclipse.org/legal/epl-v10.html 7 # 8 # Contributors: 9 # IBM Corporation - initial API and implementation 10 #******************************************************************************* 11 #!/bin/sh 12 13 # simple sample script to fire an email from the local machine to some user to 14 # notify them of a change to the watched feed 15 16 # Requirements: 17 # tested on Debian (Kubuntu), using 18 # exim 3.36-16 19 # mailx 1:8.1.2-0.20040524cvs-4 20 21 debug=0; 22 feedURL=""; 23 xpath=""; 24 newvalue=""; 25 oldvalue=""; 26 27 while [ "$#" -gt 0 ]; do 28 case $1 in 29 '-debug') 30 debug=$2; 31 shift 1 32 ;; 33 '-feedURL') 34 feedURL=$2; 35 shift 1 36 ;; 37 '-xpath') 38 xpath=$2; 39 shift 1 40 ;; 41 '-oldvalue') 42 oldvalue=$2; 43 shift 1 44 ;; 45 '-newvalue') 46 newvalue=$2; 47 shift 1 48 ;; 49 esac 50 shift 1 51 done 52 53 if [ $debug -gt 0 ]; then 54 echo "[sendEmailAlert] Started `date +%H:%M:%S`. Executing with the following options:" 55 echo "-debug $debug"; 56 echo "-feedURL $feedURL"; 57 echo "-xpath $xpath"; 58 echo "-oldvalue $oldvalue"; 59 echo "-newvalue $newvalue"; 60 fi 61 62 tmpfile="/tmp/sendEmailAlert.sh.tmp"; 63 echo "" > $tmpfile; 64 65 # compose message 66 echo "Eclipse RSS Feed has been updated." >> $tmpfile; 67 echo "" >> $tmpfile; 68 echo "Here's what happened:" >> $tmpfile; 69 echo "" >> $tmpfile; 70 71 if [ "x$xpath" != "x" ]; then echo "Changed Node: "$xpath >> $tmpfile; fi 72 if [ "x$oldvalue" != "x" ]; then echo "Old Value: "$oldvalue >> $tmpfile; fi 73 if [ "x$newvalue" != "x" ]; then echo "New Value: "$newvalue >> $tmpfile; fi 74 if [ "x$feedURL" != "x" ]; then echo "Feed URL: "$feedURL >> $tmpfile; fi 75 76 echo "" >> $tmpfile; 77 78 #assemble mail info 79 toAddress="codeslave (at] ca.ibm.com"; 80 fromAddress="Eclipse Build Team <NOSUCHADDRESS (at] eclipse.org>"; 81 subject="Eclipse RSS Feed Updated!"; 82 MAIL="/usr/bin/mail"; 83 84 if [ $debug -gt 0 ]; then 85 echo "Sending the following email using "$MAIL":"; 86 echo "--"; 87 echo "Subject: "$subject; 88 echo "To: "$toAddress 89 echo "From: "$fromAddress 90 echo "--"; 91 cat $tmpfile; 92 echo "--"; 93 fi 94 95 # send message 96 cat $tmpfile | $MAIL -s "$subject" -a "From: $fromAddress" $toAddress; 97 98 # cleanup 99 rm -fr $tmpfile; 100 101 if [ $debug -gt 0 ]; then 102 echo "Done."; 103 fi 104