#!/bin/sh #Used for email alerting of incoming calls #Written by Matt Schmandt #version .1 #License: GPL #$1 email address #$2 callerid num #$3 callerid name #$4 dial status #$5 vm status #Store command line args in nice variables EMAIL=$1 CALLERIDNUM=$2 CALLERIDNAME=$3 DIALSTATUS=$4 VMSTATUS=$5 LOGFILE="/var/log/processCallEmail.log" MAILCMD="mailx -s" SUBJECT="call" SENDMAIL=1 #Set to 1 if you want it to email the alert. 0 is useful for debugging. DEBUG=0 #Set to 0 for standard operation. 1 will log inputs and mail commands for debugging. #log mail command if [ $DEBUG -eq 1 ]; then echo $1 $2 \"${3}\" $4 $5 >> $LOGFILE fi #Check we have an email address if not quit if [ "$EMAIL" == "" ]; then exit 0 fi #check for call canceled. ex. 1 ring then hangup if [ $DIALSTATUS == "CANCEL" ]; then BODY="${CALLERIDNAME} (${CALLERIDNUM}) hung up quickly." fi #check for answered call. ex. someone picks up if [ $DIALSTATUS == "ANSWER" ]; then # BODY="$CALLERIDNAME ($CALLERIDNUM) was answered by $PEERNAME." # Use the above line if you want alerts about answered calls. # At work this is not useful but at home it is. :) exit 0 fi #check for unanswered call. ex. phone rang and no one picked up if [ $DIALSTATUS == "NOANSWER" ]; then BODY="${CALLERIDNAME} (${CALLERIDNUM}) hung up." #check for hangup in vm menu. ex call went to vm and user hung up if [ $VMSTATUS == "USEREXIT" ]; then BODY="$CALLERIDNAME ($CALLERIDNUM) hung up on vm." fi #check for hangup in vm menu. ex call went to vm and user hung up if [ $VMSTATUS == "FAILED" ]; then BODY="$CALLERIDNAME ($CALLERIDNUM) hung up on vm." fi #if they left a vm we already would get an email. Don't need a 2nd if [ $VMSTATUS == "SUCCESS" ]; then exit 0 fi fi #log mail command if [ $DEBUG -eq 1 ]; then echo $BODY $MAILCMD $SUBJECT $EMAIL >> $LOGFILE fi #send email if [ $SENDMAIL -eq 1 ]; then `echo $BODY | $MAILCMD $SUBJECT $EMAIL` fi exit 0