Script for send mail for missed calls

Hey guys, the following script sends an email when there is a missed call. Now I need to add a new functionality. As we have 5 different trunks, I have to extend the script in such a way that the name of the trunk through which an incoming call has been placed is also written in the email. Can you help me? Thanks in advance!

[code][user@domain agi-bin]# vi processCallEmail.sh
EMAIL=$1
CALLERIDNUM=$2
CALLERIDNAME=$3
DIALSTATUS=$4
VMSTATUS=$5
Extension=$6

LOGFILE="/var/log/asterisk/mail-notify/processCallEmail.log"

MAILCMD="mailx -s"
SUBJECT="Missed call from $3 (phone $2)"
SENDMAIL=1 #Set to 1 if you want it to email the alert. 0 is useful for debugging.
DEBUG=1 #Set to 0 for standard operation. 1 will log inputs and mail commands for debugging.

replase extensions from GSM slots

if [ $Extension -eq 1111111111111 ]; then
Extension="Slot_1"
fi

if [ $Extension -eq 2222222222222 ]; then
Extension="Slot_2"
fi

if [ $Extension -eq 3333333333333 ]; then
Extension="Slot_3"
fi

if [ $Extension -eq 4444444444444 ]; then
Extension="Slot_4"
fi

#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

#log mail command
if [ $DEBUG -eq 1 ]; then
echo $BODY $MAILCMD $SUBJECT $EMAIL - date +%A date +%D date +%R. status $DIALSTATUS. Dialed number $Extension. >> $LOGFILE
fi

BODY=“You missed a call from $CALLERIDNAME ($CALLERIDNUM) at date +%A date +%D date +%R. (status $DIALSTATUS). Dialed number $Extension.”

#send email
if [ $SENDMAIL -eq 1 ]; then
echo $BODY | $MAILCMD "$SUBJECT" $EMAIL
fi

exit 0
[/code]

Okay, can I set the name of a trunk to a variable and use it in the script?

What do you mean by the name of a trunk? It is possible that the channel name ${CHANNEL} includes the information you want, but it will depend on how you identify a trunk and the details of your dialplan.

In the sip.conf file I have put information a about the trunks. For example:

[trunk1]
type=blabla
context=blabla
host:blabla
secret:blabla

[trunk2]
type=blabla
context=blabla
host:blabla
secret:blabla

[trunk3]
type=blabla
context=blabla
host:blabla
secret:blabla

If there is a missed call, I’m currently getting only the number of the caller and sending it to the person who has the missed call. Now I want him to also get the trunk who has been used to place the call with.

For example: You have a missed call from 02456345. The call took place over [trunk1] or [trunk2] [or trunk3]. Thank is what I mean. Thanks

The first part of the channel name or ${CHANNEL(peername)}, assuming the dialplan is running on the original channel.

Generally, though, if the handling of calls is different, the peers should have different contexts associated with them.