Merge branch 'master' of caffeine:/users/www/www/
[mspang/www.git] / unix102 / tickets_email.sh
1 #!/bin/bash
2 # Sends email when Beta tickets are available.
3
4 TEST=`mktemp`
5 wget -q --no-check-certificate https://ticketdriver.com/betawater/buy/tickets/ -O ${TEST}
6
7 LINEMATCH=`mktemp`
8 egrep '2012-04-13|Laidback|Luke' ${TEST} >> ${LINEMATCH}
9
10 if [ $? = 0 ]; then
11    SUBJECT="BUY BETA TICKETS"
12    EMAIL=$1
13    EMAILBODY=`mktemp`
14    NUMBER=$2
15
16    echo "tickets_email: Tickets available!!
17 https://ticketdriver.com/betawater/buy/tickets/" >> "${EMAILBODY}"
18    echo -e "\nMatching line: " >> "${EMAILBODY}"
19    cat "${LINEMATCH}" >> "${EMAILBODY}"
20    
21    mail -s "${SUBJECT}" "${EMAIL}" < "${EMAILBODY}"
22    if [ $NUMBER -n "" ]; then
23       echo "go buy tickets" | mail -s "${SUBJECT}" "${NUMBER}@msg.telus.com"
24    fi
25    rm "${EMAILBODY}"
26 fi
27
28 rm "${TEST}" "${LINEMATCH}"