3

What I want is this:

Having a file called file somewhere in the filesystem with a content something like:

#!/bin/whatever-interpreter-you-want
echo 'line1'
echo 'line2'

When ANY (almost any since must exist a way to edit the script itself) program opens file to read it gets:

line1
line2

As its contents instead of:

#!/bin/whatever-interpreter-you-want
echo 'line1'
echo 'line2'

Something like file contents being executed on the fly by the filesystem or the kernel itself (please, no cron, no inotify, no duct tape).

marked as duplicate by Anthon, jimmij, Jakuje, Archemar, slm linux Apr 3 '16 at 15:11

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    Can you please explain what you need this for? There might be a simpler way to accomplish it. – Joseph R. Aug 12 '15 at 6:12
  • I don't think what you want is possible: A file is either executed or read. – Fiximan Aug 12 '15 at 7:59
  • If you are willing to open a different file, then the different file can be a pipe, and the program would have to be modified to write to the pipe, close the pipe, and loop (in case the file was opened for reading again). – Robert Jacobs Aug 12 '15 at 19:11
  • @JosephR. My question is largely hypothetical, but I can think in something like a system with centralized configuration in Sqlite database and /etc/ full of these scripts querying such database when a daemon (or another program) opens them for reading. I've discarded cron because I want the files contents being generated just before they are opened, and I don't want a daemon regenerating these files from time to time. I don't know if applicable, but I discarded inotify too because I consider it very linux-specific. – matihus Aug 12 '15 at 19:23
  • 1
2

This can certainly be achieved using FUSE. Without exact details of your goals I've provided some details of FUSE below.

1

You might put your file in some FUSE filesystem. You'll then need to write some FUSE server to handle IO to such files. It might take you some significant effort (so I am not sure it is worth the pain)

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