FILE() not working with variables in the parameter

I’m struggling with the last hurdle to make my message queueing Asterisk script up and running. With FILE() I’m reading lines of the files where the messages that failed to be delivered are stored. With a fixed path, just for testing, it is working but when I use the path build up from a static part and a couple of variables it is not working and generating error messages in the cli. (cannot open, no such file or directory, is not a line-based file) while I’m 100 % sure that the file is there, ok and ready to be processed. Any suggestion or pointer is very welcome. Thanks in advance.



; PATH5 is the variable that holds the path and the file name of the .queue file to be processed
exten => s,n,Set(PATH5=/var/spool/asterisk/message_queue/${NUMBER_TO_PROCESS}/${STORED_MESSAGE_FILE_NAME})
; this is where the first line of the .queue file is read.
; this first line can be used as the parameters needed for MessageSend()
; This is working :-) while using the fixed path but then I'm resending the same message over and over again.
; When I use the line needed to work I got an error message in the CLI
;exten => s,n,Set(MESSAGESEND_PARAMETERS=${FILE(/var/spool/asterisk/message_queue/5554/1479519201-5554.queue,0,1,l)})
exten => s,n,Set(MESSAGESEND_PARAMETERS=${FILE(${PATH5},0,1,l)}) ; not working
; this is where the actual message is read into ${MESSAGE(body)} variable
; with the fixed path it is also working
;exten => s,n,Set(MESSAGE(body)=${FILE(/var/spool/asterisk/message_queue/5554/1479519201-5554.queue,1,1,l)})
exten => s,n,Set(MESSAGE(body)=${FILE(${PATH5},1,1,l)}) ; not working

; this is where the actual message is resend. It works with a fixed path
exten => s,n, MessageSend(${MESSAGESEND_PARAMETERS}) ; the first line of the .queue file.

This is the cli output. The problem seems to be the use of variables in the path. I have tried everything I could think of but no success until now.

   -- Executing [s@step3_resending_messages:2] Set("SIP/5556-00000095", "PATH5=/var/spool/asterisk/message_queue/5556/1479552996-5556.queue
    -- ") in new stack
[Nov 20 16:24:20] ERROR[7991][C-0000009e]: func_env.c:449 file2format: Cannot open '/var/spool/asterisk/message_queue/5556/1479552996-5556.queue
': No such file or directory
[Nov 20 16:24:20] WARNING[7991][C-0000009e]: func_env.c:586 file_read: '/var/spool/asterisk/message_queue/5556/1479552996-5556.queue
' is not a line-based file

When I use the path named as invalid in the cli, it seems to be ok. With output as expected. Part of the first line isn’t showed on this forum but it is there.

XXXX@hkcc:/home/erik# cat /var/spool/asterisk/message_queue/5556/1479553232-5556.queue
sip:5556,5554 <;transport=UDP>

You appear to have a newline character at the end of the file name in the script. Unix/Linux filenames can contain newlines, so a newline there will not be ignored.

Thanks for the response and pointer. I find another way to fix it and it is now up and running with some minor adjustments to be made. Not the most graceful way but it is working. Still curious how it can be done with File() without any problem. How can a new line character be stripped from a variable value?

; a script is run to create two files, temp1 and temp2
; temp1 contains the first line of the .queue file in process holding the parameters for MessageSend()
; temp2 contains the second line of the .queue file in process holding the actual message
; this is the script at /var/spool/asterisk/message_queue_process/line-script
;sed -n ‘1{p;q;}’ “$name” > /var/spool/asterisk/message_queue_process/temp1.tmp
;sed -n ‘2{p;q;}’ “$name” > /var/spool/asterisk/message_queue_process/temp2.tmp

exten => s,n, System(/var/spool/asterisk/message_queue_process/line-script ${PATH5})
exten => s,n,Set(MESSAGESEND_PARAMETERS=${FILE(/var/spool/asterisk/message_queue_process/temp1.tmp,0,1,l)})
; this is where the actual message is read into ${MESSAGE(body)} variable
exten => s,n, Set(MESSAGE(body)=${FILE(/var/spool/asterisk/message_queue_process/temp2.tmp,0,1,l)})