Good place to read and write data used by a cron script?
I am writing a script that needs to be executed hourly. It basically works like:
- Read the data file if it exists.
- Take action if the data file has specific content.
- Write down or create a data file.
I'll put a script in / etc / cron.hourly / on Ubuntu that will make it execute once an hour.
What's a good place to store a data file? The script is executed as root.
First, both the data file and the cron job must be named after your application. Secondly, if I understand correctly, your data is modified by a cron job and is not human-edited. Thus, the "File System Hierarchy Standard" says that if an application has a name foo
, then there should be a cron job /etc/cron.hourly/foo
and a data file should be /var/lib/foo
. The reason is that the goal /var/lib
is set like this:
This hierarchy contains state information related to an application or system. State information is data that programs change when they run and that are specific to one particular host. Users do not need to modify the files in
/var/lib
to customize the batch operation.
a source to share
The subdirectory /var
is the right place for data to be read and modified by the system. See File System Hierarchy for more information .
a source to share
If it is temporary data, then / tmp or / var / tmp are standard directories. Persistent data can be placed in any area of the file system that a process can read and write. I usually create a "data" directory somewhere in the tree where the process has write permissions like ~ / data, / app / data, etc.
a source to share