#!/bin/bash # #Author: Adam Bumpus #Date: 01/19/2001 #Last Modified: 08/13/2001 # #This script compares my mail spool against a 30 second old copy. If there # are any differences it sends a message to my cellular phone containing #the From: and Subject lines of the message that changed. # #08/13/2110: fixed some bonehead bugs. If you have the 08/06/2001 version #change to this one now. # #08/06/2001: updated script. Renamed some variables for clarity and improved #system for checking for new mail. The new system counts messages rather than #lines in the spool, this should help prevent blank or duplicate messages from #being sent to a phone. #Also added a configuration values section to make it easier for people who are #not me to use this script. # #phonenumber should be pretty easy to fill in #mailspool describes where your mail is stored on your unix system #a common place is /var/mail/username or /var/spool/mail/username. #url1 and url2 will depend on your provider. The example values filled #in here are for US Cellular. Other systems will be similar in format, #but different in the exact details. # #Todo: Update to avoid messages on deleteing mail. DONE # Change to send web requests rather than e-mail DONE # Include some message body of incoming e-mail # Fix Problems after deleting e-mails DONE # eliminate need to copy mail spool DONE # #CONFIGURATION VALUES phonenumber=########### mailspool=/var/spool/mail/username url1="http://scripts.textmsg.com/xscripts/senduscc.idc?number=$phonenumber&message=" url2="&Send=Send" deletefile="senduscc.idc*" #******** #setup baselines for mailbox oldlines=`wc $mailspool | awk '{print $1}'` oldmessages=`grep ^Message-I $mailspool -c | awk '{print $1}'` #initialize currentlines and currentmessages to known safe values currentlines=$oldlines currentmessages=$oldmessages while true ; do currentlines=`wc $mailspool | awk '{print $1}'` currentmessages=`grep ^Message-I $mailspool -c | awk '{print $1}'` sendalert=`echo "$currentmessages > $oldmessages" | bc` boxempty=`echo "$currentmessages < $oldmessages" | bc` ###Reset counters if mailbox size decreases if [ $boxempty = "1" ] then oldmessages=$currentmessages oldlines=$currentlines fi ###Send the alert if there is new mail if [ $sendalert = "1" ] ; then tail -n `echo "$currentlines - $oldlines" | bc` $mailspool >> temp fromline=`grep ^From: temp` subjectline=`grep ^Subject: temp` wget "$url1$fromline$subjectline$url2" > /dev/null rm temp rm $deletefile oldmessages=$currentmessages oldlines=$currentlines fi sleep 30 done