3

So the specific problem is that I want a file on my system to link to a http url, but fallback to a local version if there's no connection. The catch is that the program reading this file will be expecting css and so won't, by default, execute any access/fallback script I put in the file.

This got me thinking more generally:
When you access a php file on a webserver, before you read the file contents, the php script is interpreted. As far as any program accessing the file is concerned, the contents are the output (I know this only works because you are accessing it over http).

Does anyone know of an equivalent for local files? I'm aware that I could just setup apache and use a local http request to get exactly this behaviour from php, but I was interested to know if it was possible without that.

I am running Ubuntu 16.04 in case that makes a diference

  • I don't think something like this exists, but I like your question! – mtak May 23 '17 at 6:32
  • Check my updated answer. – Kamil Maciorowski Jul 4 '17 at 14:05
2

In general the /proc filesystem works in a similar way, I think. Follow The Linux Kernel Module Programming Guide.

Or create your own FUSE which will work in user space.

Edit
There is a FUSE that seems to do just that: ScriptFS. Its README says:

ScriptFS is a new file system which merely replicates a local file system, but replaces all files detected as "scripts" by the result of their execution.

Any script is supported. In a usual way of working, ScriptFS reads on its command line the name of two programs : one that is the script interpretor, and the other one a lightweight program that tells fast if a file on the disk is a script that can be read by the first program.

I guess if you build these two programs right, they will be able to use shebangs.

Note: I have never used ScriptFS (yet).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.