In Linux, I would like to create a file where the contents of the file are dynamically generated by the output of a program.
The examples which already exist are /dev/random /dev/urandom, /dev/zero, etc...
I would like to create a file such as /home/sam/currentdate.txt where by the contents of the file are the result of running a command (such as date, and would read:
[sam@myserver ~]$ cat ./currentdate.txt
Wed Dec 2 12:12:09 PST 2015
[sam@myserver ~]$
For my use case, I need to track the output of certain programs by another program which can not read the contents of a program's output, but rather the contents of a file. I can save the contents of the output via a script by using date > filename.txt but that requires saving the output to disk first, which is going to be inefficient in my use case.
A named pipe may be your friend. Create a named pipe and have your process(es) write to it. Your reading process can then read from it.
This looks like an instance of the XY problem; what exactly are you trying to accomplish?
If you want to read the output of a program and use it in your script, you can call the target program and assign its output to a variable: https://stackoverflow.com/questions/4651437/how-to-set-a-bash-variable-equal-to-the-output-from-a-command.
If instead you actually want the program to run asynchronously and store its output where your script can read it, you can either use a disk file (which really doesn't have as much overhead as you think), or a named pipe, as Iain suggested.