I have a script that emails the extension after a recording is placed to the extension that records the messages. Works fine in Freepbx 14 but I get invalid message saying it cannot find the email. I am assuming I need to update the following:
Find Email Address of recording extension
. <(grep AMPDB /etc/amportal.conf) # Source DB Creds
email="" # Blank out email arg just in case
valem="[[:graph:]]+@[[:graph:]]+.[[:graph:]]+" # Set regex to validate email addresses
trigext=$(echo -n $5 | egrep --color -o “/[0-9]{2,5}-” | egrep -o “[[:digit:]]*”) # Set Triggering extension
email="$(mysql -u$AMPDBUSER -p$AMPDBPASS -D $AMPDBNAME -Bse ‘select email from userman_users where default_extension = ‘${trigext}’;’ 2>/dev/null)" # Get email address for trigext from userman.
. <(grep AMPDB /etc/freepbx.conf) # Source DB Creds
email="" # Blank out email arg just in case
valem="[[:graph:]]+@[[:graph:]]+.[[:graph:]]+" # Set regex to validate email addresses
trigext=$(echo -n $5 | egrep --color -o “/[0-9]{2,5}-” | egrep -o “[[:digit:]]*”) # Set Triggering extension
email="$(mysql -u$AMPDBUSER -p$AMPDBPASS -D $AMPDBNAME -Bse ‘select email from userman_users where default_extension = ‘${trigext}’;’ 2>/dev/null)" # Get email address for trigext from userman.
You need it (and had it in your post) , it is an alias for source which is more readable that sets the variable like ‘ASTDBUSER=fred’ but freepbx.conf don’t look like that whereas amportal.conf does ,
Start with baby steps, fist
grep AMPDB /etc/freepbx.conf
will show your AMPDB creds, then replace the $AMPDB’s apropos and replace = ${trigext} with like '%NNN%' in
mysql -u$AMPDBUSER -p$AMPDBPASS -D $AMPDBNAME -Bse ‘select email from userman_users where `default_extension` = ‘${trigext}’;’
likely you won’t need a wild card for default_extension and
$DT - Set the timestamp in the MSG to one of the above timestamps
DT=$DTS
MSG="" # Initialize MSG arg
Find Email Address of recording extension
source <(grep AMPDB /etc/freepbx.conf |cut -d “’” -f2,4|tr “’” ‘=’) # Source DB Creds
email="" # Blank out email arg just in case
valem="[[:graph:]]+@[[:graph:]]+.[[:graph:]]+" # Set regex to validate email addresses
trigext=$(echo -n $var5 | egrep --color -o “/[0-9]{2,5}-” | egrep -o “[[:digit:]]*”) # Set Triggering extension
email="$(mysql -u$AMPDBUSER -p$AMPDBPASS -D $AMPDBNAME -Bse ‘select email from userman_users where default_extension = ‘${trigext}’;’ 2>/dev/null)" # Get email address for trigext from userman.
if [ "$var4"x == “x” ]
then
var4=$trigext
fi
Check that we have a valid email address
if ! [[ $email =~ $valem ]]
then
MSG="$MSG !!! No Valid email found for ${trigext} !!!\n"
MSG="$MSG !!! Defaulting to ${defem} !!!\n"
email=$defem
fi
Compile Message
MSG="$MSG You have a new call recording to listen to: \n"
MSG="$MSG The call date and time was $DT \n"
MSG="$MSG The call was from $var2 \n"
MSG="$MSG The call was to $var4 \n"
MSG="$MSG Please see the attached file \n\n"
Debug Values to add to MSG
#MSG="$MSG Attachment:\t${3}\n"
#MSG="$MSG Who Activeated:\t${5}\n"
#MSG="$MSG WhoAct-Basic:\t${trigext}\n"
#MSG="$MSG Email Addr:\t${email}\n"
Testing Destination so you don’t have to flood an email box
echo -e “$MSG” >> /tmp/recording-script.log
Email MSG and attachment
echo -e “$MSG” | which mail -a $var3 -s “New Call Recording” $email
> #!/bin/bash
>
> # This script emails the recorded call right after the call is hung up. Below are the variables passed through asterisk
> # Post Recording Setting in Advanced Settings = "/var/lib/asterisk/bin/recordscript.sh ^{TIMESTR} ^{CRM_SOURCE} ^{MIXMONITOR_FILENAME} ^{DIALEDPEERNUMBER} ^{DYNAMIC_WHO_ACTIVATED}"
> # $1 - Time String
> # $2 - Source
> # $3 - File
> # $4 - Destination
> # $5 - Who activated recording
> # $6 - This extension in case destination is empty use this
>
> var1=$(echo $1 | cut -f2 -d=) # timestamp
> var2=$(echo $2 | cut -f2 -d=) # source
> var3=$(echo $3 | cut -f2 -d=) # file name
> var4=$(echo $4 | cut -f2 -d=) # destination
> var5=$(echo $5 | cut -f2 -d=) # who activated
> var6=$(echo $6 | cut -f2 -d=) # this extension -> destination
> echo -e "$var1 $var2 $var3 $var4 $var5 $var6" >> /tmp/recording-script.log
> # Default Email to use incase we don't get a valid match
> defem="[email protected]"
>
> # $DTS - Date & Time the recording started
> DTS=$(date '+%m/%d/%Y %r' --date="$(echo -n "$var1" | sed -r 's/([0-9]{4})([01][0-9])([0-3][0-9])-([0-2][0-9])([0-5][0-9])([0-5][0-9])/\1\/\2\/\3 \4:\5:\6/')" 2>/dev/null)
>
> # $DTE - Date & Time the recording ended
> DTE=$(date '+%m/%d/%Y %r')
>
> # $DT - Set the timestamp in the MSG to one of the above timestamps
> DT=$DTS
>
> MSG="" # Initialize MSG arg
>
> # Find Email Address of recording extension
> source <(grep AMPDB /etc/freepbx.conf |cut -d "'" -f2,4|tr "'" '=') # Source DB Creds
> email="" # Blank out email arg just in case
> valem="[[:graph:]]+@[[:graph:]]+\.[[:graph:]]+" # Set regex to validate email addresses
> trigext=$(echo -n $var5 | egrep --color -o "\/[0-9]{2,5}-" | egrep -o "[[:digit:]]*") # Set Triggering extension
> email="$(mysql -u$AMPDBUSER -p$AMPDBPASS -D $AMPDBNAME -Bse 'select email from userman_users where `default_extension` = '${trigext}';' 2>/dev/null)" # Get email address for trigext from userman.
> if [ "$var4"x == "x" ]
> then
> var4=$trigext
> fi
> # Check that we have a valid email address
> if ! [[ $email =~ $valem ]]
> then
> MSG="$MSG !!! No Valid email found for 1000 !!!\n"
> MSG="$MSG !!! Defaulting to ${defem} !!!\n"
> email=$defem
> fi
>
> # Compile Message
> MSG="$MSG You have a new call recording to listen to: \n"
> MSG="$MSG The call date and time was $DT \n"
> MSG="$MSG The call was from $var2 \n"
> MSG="$MSG The call was to $var4 \n"
> MSG="$MSG Please see the attached file \n\n"
>
> ## Debug Values to add to MSG
> #MSG="$MSG Attachment:\t${3}\n"
> #MSG="$MSG Who Activeated:\t${5}\n"
> #MSG="$MSG WhoAct-Basic:\t${trigext}\n"
> #MSG="$MSG Email Addr:\t${email}\n"
>
> ## Testing Destination so you don't have to flood an email box
> echo -e "$MSG" >> /tmp/recording-script.log
>
> # Email MSG and attachment
> echo -e "$MSG" | `which mail` -a $var3 -s "New Call Recording" $email
>
> exit 0
where $Var5 is ^{DYNAMIC_WHO_ACTIVATED}, which the fifth parameter in the call to the script, just replace initially ${trigext} with 1000 to test. (color !! WTF is that doing there!! )
paste a sample ^{DYNAMIC_WHO_ACTIVATED} and we can likely write a nice sed expression