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.

+1


a source to share


5 answers


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.

+4


a source


/opt

and / or /var

are usually good places to do this. Obviously narrow it down from there.



+2


a source


The subdirectory /var

is the right place for data to be read and modified by the system. See File System Hierarchy for more information .

+1


a source


If it is read-only data:

/usr/local/share/program_name

      

If it is a config file (or files):

/usr/local/etc/program_name

      

Unless it's something very specific that should go into / var / spool, / var / run, or wherever. There's also a school /opt/XXX

...

0


a source


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.

0


a source







All Articles