Run after record

I am trying to give my recordings in /var/spool/asterisk/monitor a “from” and “to” identifier.

I have a script running called /var/lib/asterisk/bin/sortcalls.sh It is this:

#!/bin/sh
//
DATE=date -r $2$1 +'%Y/%m-%b/%d-%a'
//
mkdir -p $2$DATE
//
UNIQUEID=echo $1 |sed "s/.*\-\([.0-9]*\)\.[a-zA-Z]*$/\1/"
//
FILETYPE=echo $1 |sed "s/.*\-[.0-9]*\(\.[a-zA-Z]*$\)/\1/"
//
NEWFILE=/usr/bin/mysql -u root -peLaStIx.2oo7 -N -B -D asteriskcdrdb -e "SELECT calldate,'From:',clid,'To:',dst,'' FROM cdr WHERE uniqueid = $UNIQUEID LIMIT 1"|sed -e 's/\s/_/g' -e "s/_$/$FILETYPE/" -e "s/["<>]//g"
//

if [ ! -f $2$DATE/$NEWFILE ] ;then ln $2$1 $2$DATE/$NEWFILE ;fi
#There appears to be something missing from this last line, as it stops after “fi”. The script is not mine.

Then I have in my General Settings Recording Location: /var/spool/asterisk/monitor/

And in the Run after record:

/var/lib/asterisk/bin/sortcalls.sh ^${MIXMON_DIR}/^{CALLFILENAME}.^{MIXMON_FORMAT} ^{MIXMON_DIR}//usr/bin/mysql -u root -peLaStIx.2oo7 -N -B -D asteriskcdrdb -e "SELECT calldate,'From:',src,'To:',dst,'' FROM cdr WHERE uniqueid = ^{UNIQUEID}"|sed -s s'/\s/_/ g'.^{MIX

#The problem is that the box chops off the last part of the Run after record command. It is supposed to end with .^{MIXMON_FORMAT}, but it is chopping off the last part after “MIX”.

If someone knows of a easier way to do this I would appreciate the help. Need to name the recordings with something a user can understand, and then upload them to an FTP site.

Something like this posts to /var/spool/asterisk/monitor:
drwx------ 2 asterisk asterisk 4096 Apr 1 13:39 2011-04-01_13:38:46_From:callingnumber_To:outnumber.
drwx------ 2 asterisk asterisk 4096 Apr 1 13:39 2011-04-01_13:39:05_From:
To:.
drwx------ 2 asterisk asterisk 4096 Apr 1 13:40 2011-04-01_13:40:19_From:
To:.
drwx------ 2 asterisk asterisk 4096 Apr 1 13:40 2011-04-01_13:40:35_From:
To:_.
-rw------- 1 asterisk asterisk 220204 Apr 1 13:39 OUT1000-20110401-133846-1301690326.32.wav
-rw------- 1 asterisk asterisk 144044 Apr 1 13:39 OUT1000-20110401-133905-1301690345.34.wav
-rw------- 1 asterisk asterisk 166124 Apr 1 13:40 OUT1000-20110401-134020-1301690419.36.wav
-rw------- 1 asterisk asterisk 165484 Apr 1 13:40 OUT1000-20110401-134035-1301690435.38.wav

It creates a folder with the “From” and “To” that has nothing it it, and the call record with the unique ID. I am assuming it is doing this because the Run after record command is incomplete.

Thanks.

Hi Franklin,

I use a file: /var/lib/asterisk/bin/sendrecordingbyemail that contains:

[code]#!/bin/bash

Call script from FreePBX after call ended using Run After Record (2.8) or Post Call Recording Script (2.9)

Use parameters of /var/lib/asterisk/bin/sendrecordingbyemail ^{CALLFILENAME}.^{MIXMON_FORMAT} ^{UNIQUEID}

get the CDR for the record

DETAILS=/usr/bin/mysql -u asteriskuser -pasteriskuserZ2q -N -B -D asteriskcdrdb -e "SELECT * FROM cdr WHERE uniqueid = '$2'"

Email the recording with the CDR details

echo “$DETAILS” |mutt -x -a /var/spool/asterisk/monitor/$1 -s “$1” email@destination
[/code]

You need to have mutt and you should alter the SELECT * statement to extract just the info you need. I select all columns as I then import everything into my call recorder. You can build any string you like including altering the Subject. Set USER and PASSWORD as appropriate.

Hope this helps
Dave

Can’t Remember (Sorry the last word eludes me )

/usr/bin/mysql -u root -peLaStIx.2oo7 -N -B -D asteriskcdrdb -e “SELECT calldate,‘From:’,clid,‘To:’,dst,’’ FROM cdr WHERE uniqueid = $UNIQUEID LIMIT 1”|sed -e 's/\s//g’ -e "s/$/$FILETYPE/" -e “s/[”<>]//g"

/usr/bin/mysql -u root -peLaStIx.2oo7 -N -B -D asteriskcdrdb -e “SELECT calldate,‘From:’,clid,‘To:’,dst,’’ FROM cdr WHERE uniqueid = $UNIQUEID LIMIT 1”|sed -e 's/\s//g’ -e "s/$/$FILETYPE/" -e “s/[”<>]//g"

you need to escape the " character in the sed expression

Carrier Routing System, a large-scale core router, developed by Cisco Systems, Inc
or
Chinese restaurant syndrome, purportedly caused by the flavor enhancer glutamate
?

I remember even with my CRS, writing a script something like that but it is not quite verbatim.

It’ not very rigorous and pretty damn ugly but generally works, Caveat implementor:-

get rid of the

//

lines they are not commentary in bash # is

the script is called with two arguments

$2 is the directory in which the filename $1 will be found

call the script from General Settings Recording with just those two arguments thusly:

/var/lib/asterisk/bin/sortcalls.sh ^${MIXMON_DIR}/^{CALLFILENAME}.^{MIXMON_FORMAT} ^{MIXMON_DIR}

p.s. maybe back to the bash tutorial :slight_smile: :slight_smile:

#!/bin/sh

DATE=date -r $2$1 +'%Y/%m-%b/%d-%a'

mkdir -p $2$DATE

UNIQUEID=echo $1 |sed "s/.*\-\([.0-9]*\)\.[a-zA-Z]*$/\1/"

FILETYPE=echo $1 |sed "s/.*\-[.0-9]*\(\.[a-zA-Z]*$\)/\1/"

NEWFILE=/usr/bin/mysql -u root -peLaStIx.2oo7 -N -B -D asteriskcdrdb -e "SELECT calldate,'From:',clid,'To:',dst,'' FROM cdr WHERE uniqueid = $UNIQUEID LIMIT 1"|sed -e 's/\s/_/g' -e "s/_$/$FILETYPE/" -e "s/["<>]//g"

if [ ! -f $2$DATE/$NEWFILE ] ;then ln $2$1 $2$DATE/$NEWFILE ;fi

there is no nextline until you add it or insert previous lines perhaps to

use sox to normalize levels if you use dahdi and haven’t bothered to set it up right

use sox to strip off the ringing tone , subtract calltime from answertime and start with that offset,and then the silence at either end, (watch out for the wink at the end of dahdi calls and remove the last 500 milliseconds)

use lame to convert to mp3 to save space,and id2tag appropriately with extension datetime etc.

use mail and mutt to email to the users email or cellphone, parse /etc/asterisk/voicemail.conf to get the address

the world is your oyster . . .

and

/var/lib/asterisk/bin/sortcalls.sh ^${MIXMON_DIR}/^{CALLFILENAME}.^{MIXMON_FORMAT} ^{MIXMON_DIR}

produces in /monitor/ only

-rw------- 1 asterisk asterisk 234284 Apr 2 01:12 OUT1000-20110402-011203-1301731923.0.wav

is seems the following line is missing the endpart where it would command to write the standard output of NEWFILE to some place ?

if [ ! -f $2$DATE/$NEWFILE ] ;then ln $2$1 $2$DATE/$NEWFILE ;fi

I am trying to ftp recording outside my asterisk once a call recording is completed. I have added the following line in the Run After Record field in the general settings:
/var/lib/asterisk/bin/ftprecording ^{MIXMON_DIR}/^{CALLFILENAME}.^{MIXMON_FORMAT}

So this expects one argument in my script. My script looks like this:
----------------START-----------
#!/bin/bash

Run After script once call recording is completed (hang-up event)

Use parameters of /var/lib/asterisk/bin/ftprecording ^{MIXMON_DIR}/^{CALLFILENAME}.^{MIXMON_FORMAT}

FTP the recording

HOST=192.168.3.13
ftp -inv $HOST<<ENDOFUPLOAD
user sroch123 sroch123
bin
hash
put $1
bye
ENDOFUPLOAD
----------END-SCRIPT------------

I can see the script gets invoked because my FTP does get a successful login. But there is no file ftp’ed presumably because of the argument passing is incorrect. Can someone tell me what I’m doing wrong? Or is there a but in FreePBX about this functionality?

thx in advance
Stephane

there was a mistake in my previous posting of the script, the script should read as follows:
--------START-------------
#!/bin/bash

Run After script once call recording is completed (hang-up event)

Use parameters of /var/lib/asterisk/bin/ftprecording ^{MIXMON_DIR}/^{CALLFILENAME}.^{MIX

MON_FORMAT}

FTP the recording

HOST=192.168.3.13
ftp -inv $HOST<<ENDOFUPLOAD
user sroch123 sroch123
bin
hash
put $1
bye
ENDOFUPLOAD
-----------END-----------

posting again as I used the wrong input format (now Filtered HTML)
----------START----------
#!/bin/bash

Run After script once call recording is completed (hang-up event)

Use parameters of /var/lib/asterisk/bin/ftprecording ^{MIXMON_DIR}/^{CALLFILENAME}.^{MIX

MON_FORMAT}

FTP the recording

HOST=192.168.3.13
ftp -inv $HOST<<ENDOFUPLOAD
user sroch123 sroch123
bin
hash
put $1
bye
ENDOFUPLOAD
-----------END-------------

Here’s the script again in full:

#!/bin/bash

Run After script once call recording is completed (hang-up event)

Use parameters of /var/lib/asterisk/bin/ftprecording ^{MIXMON_DIR}/^{CALLFILENAME}.^{MIX

MON_FORMAT}

FTP the recording

HOST=192.168.3.13
ftp -inv $HOST<<ENDOFUPLOAD
user sroch123 sroch123
bin
hash
put $1
bye
ENDOFUPLOAD

The MIXMON_DIR does not exist on the server so the upload is failing.
Try using

put $1 basename $1

instead of put $1

Can anyone please create a script that compresses the file then uploads the compressed file via ftp, then deletes the compressed file?

I wonder though, would that be too cpu intensive for a the pbx?