Executing Script after MixMonitor is called

Home » Asterisk Users » Executing Script after MixMonitor is called
Asterisk Users 9 Comments

Hello Guys,
I am trying to convert files that are .wac to mp3 after mixmonitor command is called but it doesnt execute the command, I tried the command in terminal it worked, any help please … below is my dial plan
exten=6500,n,Set(MIXMONITOR_EXEC=&& nice -n 19 /usr/local/bin/lame -b 8 -t -F -m m –bitwidth 8 –quiet “/var/spool/asterisk/monitor/${CALLFILENAME}.wav” “/var/spool/asterisk/monitor/${CALLFILENAME}.mp3” && rm -f “/var/spool/asterisk/monitor/${CALLFILENAME}.wav”)

9 thoughts on - Executing Script after MixMonitor is called

  • On Thu, Jan 26, 2012 at 7:36 PM, Steve Edwards

    Wow. Never knew that was possible. I still don’t like the syntax, but
    good to know.

    For optimal debugging, I would suggest OP not try to build the
    pyramids with a single line of commands joined by ampersands, but
    rather do a separate System() call for either doing my script idea or
    doing the individual commands in multiple separate System() calls.

  • Hi Satish,

    I tried with sox, without any parameter, just sox filename.wav to filename.mp3, in linux shell prompt… the file is been converted…

    Now If i want to run that command using dialplan,

    Monitor_Exec(sox filename.wav filename.mp3)

    Or to use System command?


  • Hi Gopamkrishnan,

    Check the ‘command’ argument for Mixmonitor. Mixmonitor itself has a facility to execute a command when recording is over.

    *In my case, ‘wav2mp3’ is a script which gets executed and converts recorded wav audio file to mp3. I pass ${FILENAME} as an argument to my script.

    *You should have something like
    in your dialplan.

    Hope this helps.

    –Satish Barot

    Ahmedabad, India

  • And yes if you want to use System application in your dialplan then have System in your h extension

    System(/PathToSox/sox -r 8000 -c 1 /PathToWavFile/filename.wav
    /PathToMp3FileToBE Stored/filename.mp3)

  • I tried with hangup cause but my script is not executed… also I tried the same script with mix monitor itself no sucess.

    The script what I have is, am converting wav file to flac format..

  • exten => _4X.,1,Set(START_TIME=${STRFTIME(${EPOCH},,%Y-%m-%d_%H:%M:%S)})
    ;exten =>
    exten =>
    exten =>
    exten => _4X.,n,Dial(SIP/${EXTEN},30)
    exten => _4X.,n,Hangup


  • Some observations,
    (1) You are missing ^ in command in Mixmonitor.In your case, It should be something like MixMonitor(IND_PRI/${CDR(accountcode)}/OUT/${STRFTIME(${EPOCH},,%Y-%m)}/${STRFTIME(${EPOCH},,%d)}/${MIXMONITOR_FILENAME}.wav,m,/root/flac.sh
    (2) You are passing just file name as a parameter in your script and not a full path for file. (Do you handle full path in a script?)

    –Satish Barot Ahmedabad, India

  • I tried with the ^ symbol but still there is no success.

    And regards to the path, actually my file is in path /root, is that to be in /usr/sbin or somewhere?

    Basically am able to see the application executed in the CLI, like the below,

    Executing [4090@test:1] Set(“SIP/4092-0000003b”,
    “START_TIME 13-07-05_14:43:11”) in new stack
    — Executing [4090@test:2] Set(“SIP/4092-0000003b”,
    “MIXMONITOR_FILENAME@90-2013-07-05_14:43:11-OUT”) in new stack
    — Executing [4090@test:3] MixMonitor(“SIP/4092-0000003b”,
    4090-2013-07-05_14:43:11-OUT”) in new stack
    — Executing [4090@test:4] Set(“SIP/4092-0000003b”,
    in new stack
    — Executing [4090@test:5] Dial(“SIP/4092-0000003b”, “SIP/4090,30”) in new stack
    == Using SIP RTP CoS mark 5
    == Begin MixMonitor Recording SIP/4092-0000003b
    — Called SIP/4090
    — SIP/4090-0000003c is ringing
    — SIP/4090-0000003c answered SIP/4092-0000003b
    — fixed jitterbuffer created on channel SIP/4090-0000003c
    — fixed jitterbuffer created on channel SIP/4092-0000003b
    — Executing [h@test:1] MYSQL(“SIP/4092-0000003b”, “Connect connid localhost root Iopex1063 Logs”) in new stack
    — Executing [h@test:2] MYSQL(“SIP/4092-0000003b”, “Query resultid 1
    insert into call_log(accountcode,start,end,src,dst,uniqueid,userfield,hangupcause)
    in new stack
    — Executing [h@test:3] MYSQL(“SIP/4092-0000003b”, “Disconnect 1”) in new stack
    — fixed jitterbuffer destroyed on channel SIP/4090-0000003c
    == Spawn extension (test, 4090, 5) exited non-zero on ‘SIP/4092-0000003b’
    — fixed jitterbuffer destroyed on channel SIP/4092-0000003b
    == MixMonitor close filestream
    == *Executing [/root/flac.sh 4090-2013-07-05_14:43:11-OUT]*
    == End MixMonitor Recording SIP/4092-0000003b

    But the file is not converted, I suspect it could be a path issue.