Monitor filename existance

Hi all.
We set/write a Monitor filename as a CDR field (SQL).
The problem: it’s set independently of MixMonitor recorded file, either it has been created successfully or not.

Do you have any ideas, what is the beast way to check the existance of a recorded file? If it was created - then fill the CDR field, otherwise leave it blank.

I understand that we can execute some script which will check the existance of the file right after the call is ended, and then modify the SQL CDR record, but maybe there are some other variants?

Asterisk 1.8.32.3

macro record(direction,extension)
{
	switch(${direction})
	{
		case incoming_office:
			Set(REC_FILE=${UNIQUEID}_in_${CALLERID(num)});
			break;
		case outgoing_office:
			Set(REC_FILE=${UNIQUEID}_ou_${extension});
			break;
		case local_office:
			Set(REC_FILE=${UNIQUEID}_lo_${CALLERID(num)}_${extension});
			break;
		case local_operator:
			Set(REC_FILE=${UNIQUEID}_lo_${CALLERID(num)}_${extension});
			break;

		default:
			Set(REC_FILE=${UNIQUEID}_default_${CALLERID(num)});
			break;
	}

	Monitor(,"${REC_DIR}/${REC_FILE}",bm);
	Set(CDR(filename)=${REC_FILE}.wav);
	return;
}


BR, Alexey

One suggestion - use built-in dialplan function SHELL with the filename as an input parameter and a flag as an output. The flag might be set to 1 if a file is found and to 0 if otherwise.
Shell script itself would be trivial:

Filetocheck=$1
if [  -f $Filetocheck ]; then
   Flag=1
else
  Flag=0
fi
echo $Flag

In the dialplan:
SHELL(path_to_shell_script filename_to_check)

Isn’t it the time for upgrade?

use the STAT function with the ‘e’ argument.

https://wiki.asterisk.org/wiki/display/AST/Function_STAT

Thank you guys, but all this seems not to work because the file is created after Monitor is stopped. But it is stopped when the channel is destroyed. And it is destroyed after finishing of ‘h’ extension.

So it means that we can not check the existance of the recorded file for the call during the call execution.

This should be done not in dialplan but in some other script which will update then the CDR SQL table. (I know how it can be done).

From help:

By default, files are stored to “/var/spool/asterisk/monitor/”. Returns ‘-1’ if
monitor files can’t be opened or if the channel is already monitored, otherwise
‘0’.

How can I get the return code of Monitor application? The application dots not have any variables (like ${DIALSTATUS} in Dial) in which I can get either ‘-1’ or ‘0’.

There is a MIXMONITOR function you can call to check the status I believe.

https://wiki.asterisk.org/wiki/display/AST/Asterisk+13+Function_MIXMONITOR