Question regarding flow

I am implementing the Monitor() command for calls. And i have experienced a couple things. What i want to accomplish is this…
Record the calls… when the call is finished, merge the two files into a single wav and then email me the wav. All of which work fine per se , the problem is in the timing.

When executing a block, i do this:
exten => s,1,Answer
exten => s,2,playback(pls-wait-connect-call)
exten => s,3,playback(this-call-may-be-monitored-or-recorded)
exten => s,4,Monitor(wav,TestRecord,m)
exten => s,5,Dial(SIP/2230115555551212@,g)
exten => s,6,Macro(sendRecording)

The macro looks like this:
exten => s,1,SetVar(
exten => s,2,system(mime-construct --to ${EMAILADDR} --subject “Recording” --attachment “TestRecord.wav” --type wav --file /var/spool/asterisk/monitor/TestRecord.wav)

What happens is this, the moment the call ends it fires off the email send macro which works, and AFTER this the merger of the current files happens…

Feb 28 14:28:47 VERBOSE[8680] logger.c: – Executing Macro(“SIP/”, “sendRecording”) in new stack
Feb 28 14:28:47 VERBOSE[8680] logger.c: – Executing SetVar(“SIP/”, "") in new stack
Feb 28 14:28:47 VERBOSE[8680] logger.c: – Executing System(“SIP/”, “mime-construct --to --subject “Recording” --attachment “TestRecord.wav” --type wav --file /var/spool/asterisk/monitor/TestRecord.wav”) in new stack
Feb 28 14:28:49 DEBUG[8680] cdr_addon_mysql.c: cdr_mysql: inserting a CDR record.
Feb 28 14:28:49 DEBUG[8680] cdr_addon_mysql.c: cdr_mysql: SQL command as follows: INSERT INTO cdr (calldate,clid,src,dst,dcontext,channel,dstchannel,lastapp,lastdata,duration,billsec,disposition,amaflags,accountcode,uniqueid) VALUES (‘2006-02-28 14:28:12’,‘8585761010’,‘8585761010’,‘s’,‘custom-Transfer’, ‘SIP/’,‘SIP/’,‘System’,‘mime-construct --to --subject “Recording” --attachment "Tes’,37,37,‘ANSWERED’,3,’’,‘1141154892.97’)
Feb 28 14:28:49 DEBUG[8680] chan_sip.c: update_call_counter() - decrement call limit counter
Feb 28 14:28:49 DEBUG[8680] res_monitor.c: monitor executing ( nice -n 19 soxmix “/var/spool/asterisk/monitor/TestRecord-in.wav” “/var/spool/asterisk/monitor/TestRecord-out.wav” “/var/spool/asterisk/monitor/TestRecord.wav” && rm -f “/var/spool/asterisk/monitor/TestRecord-”* )

the bold sections i want to fire in reverse order of current…

I need to wait until this process is complete before sending the email. Is there an event that I can use to call this macro so that it is outside of the scope of the call block… OR is there a way that I can schedule a recurring function ( say for instance every hour to loop through the directory and send me the file(s) )

you may use cron to sheduling some action
for edit run 'crontab -e’
add this string
*/5 * * * * for i in ls /var/spool/asterisk/monitor/*.wav|grep -v in|grep -v out; do mime-construct --to --subject “Recording” --attachment “TestRecord.wav” --type wav --file /var/spool/asterisk/monitor/$i ;done;

this is one string!!! in one line!!!

so, it sending all files from /var/spool/asterisk/monitor/ which has no ‘in’ or ‘out’ part in name , and do cheking every 5 minutes :wink:

but also you can use something like
exten => 6,1, sleep(1000);1000 second wait before send :wink:

use monitor without m-option, and use soxmix for mixing MANUALY from SYTEM command.

thanks for the quick response. I’ll check out these options.

Appreciate the help!

another way
mv which soxmix /usr/local/bin/soxmix_old
this must rename soxmix to soxmix_old
than write script
—cut here—
/usr/local/bin/soxmix_old $1 $2 $3
rm $1 $2
mime-construct --to --subject “Recording” --attachment “$3” --type wav --file $3
– cut here–
save it to /usr/local/bin/soxmix
and do
chmod a+x /usr/local/bin/soxmix

now all request to soxmix in monitor whill be to soxmix script :wink:

anather way - edit ./res/res_monitor.c and recompile asterisk