Linux – tmpfs – auto create whole path when write to file

directorylinuxtmpfs

I have mounted tmpfs .e.g.

/tmspfs/cache

As we expect, so after restart server is ram empty and all content from mount is away. It is ok. But I have in my system some full path e.g. /tmpfs/cache/user1/file – error is /tmpfs/cache/user1/ is not exist.

I cant add some checks and rmdir to software.

So question is – Is some way here, for auto create whole path before create file?

Thanks.

Best Answer

Possible with LD_PRELOAD and some libraries, depending on the software. The easiest thing might be to put something in rc.local that will create the directories as a final step in the boot procedure.

If you wanted to make sure the directories are there continuously, you could have a cron job running that created the dirs (using mkdir -p possibly).