Reading from file using FILE()


In extensions.conf I include /scripts/*/*-dialplan.conf, so for example, I have a dialplan in /scripts/test/test-dialplan.conf and Asterisk is able to load it just fine.

I also have a file /scripts/test/vars.txt, but when using the ${FILE()} function to read, it doesn’t load any content from the file.

The same function works when I read any file under /etc/asterisk/. What am I missing?


1 Like

What version of Asterisk are you using?

ah, BTW, are you running asterisk as root? If not, the user you’re running asterisk under has permissions to read the file?


It runs as asterisk, the asterisk user has permissions to that directory and its contents. (As mentioned, Asterisk can load the dialplan just fine)

Maybe the file has a problem. Have you tried creating another file in the same location to see if it works?

Same file works under /etc/asterisk/

Then, there is something permission-related. I can’t figure out why the same file will work when moved to another folder but won’t work in its original place, despite permission issues. Maybe some of our other friends on the forum might have some other ideas, as FILE() was supposed to work with files in any folder on the disk, as long as they were formatted correctly and accessible for read/write. The docs also don’t say anything about limitations on where you can put your files for FILE() to work.

You also need execute permission for all the directories on the path to the file

AKA ‘search for directories.’

Just a note that execute permission on a directory doesn’t allow you to search it: it only allows you to access items in that directory.

Read permission is the one that lets you search a directory.

And you don’[t even need execute to search it!

david@dhcppc4:~$ mkdir R-only
david@dhcppc4:~$ cd !$
cd R-only
david@dhcppc4:~/R-only$ touch a b c d e
david@dhcppc4:~/R-only$ cd ..
david@dhcppc4:~$ chmod -x R-only
david@dhcppc4:~$ ls R-only
ls: cannot access 'R-only/b': Permission denied
ls: cannot access 'R-only/d': Permission denied
ls: cannot access 'R-only/c': Permission denied
ls: cannot access 'R-only/e': Permission denied
ls: cannot access 'R-only/a': Permission denied
a  b  c  d  e
david@dhcppc4:~$ wc R-only/a
wc: R-only/a: Permission denied
david@dhcppc4:~$ chmod +x-r R-only
david@dhcppc4:~$ wc R-only/a
0 0 0 R-only/a
david@dhcppc4:~$ ls R-only
ls: cannot open directory 'R-only': Permission denied

Two three entirely orthogonal functions: execute permission to access an item, read access to see what items are there. And of course write access to put things there and take them out again. You can have one without the other(s).

Permissions shouldn’t be an issue…

[root@pbx1 ~]# ls -la / | grep scripts
drwxrwxrwx   32 asterisk asterisk   4096 Apr 15 09:20 scripts
[root@pbx1 ~]# ls -la /scripts/  | grep temp
drwxrwxrwx   3 asterisk asterisk  104 Apr 15 10:09 temp
[root@pbx1 ~]# ls -la /scripts/temp/ | grep dialplan
-rwxrwxrwx  1 asterisk asterisk  259 Apr 30 03:17 test-dialplan.conf
[root@pbx1 ~]# ls -la /scripts/temp/ | grep var
-rwxrwxrwx  1 asterisk asterisk   36 Apr 15 09:27 vars.txt

I don’t think Asterisk checks for unsafe permissions, so, although there are issues, they shouldn’t affect access to the files, if you start from the root directory. Some software does check safety and will refuse to use files with directories like that.

Incidentally, using “ls -ld” is a simpler way of looking at the permissions for directories. SELINUX can generate permission errors even when the simple ls output looks right. Whilst this was a long to ago, I found that files uploaded with file transfer applications got marked as untrusted, so could produce permission failures.

Looks like it should throw a warning if it cannot read the file, looking at the console, I don’t see any warnings.