views:

105

answers:

5

Hi,

I'm writing a script which is to be executed hourly. It basically works as:

  1. Read the datafile if it exists.
  2. Perform an action if the datafile has certain contents.
  3. Write over or create the datafile.

I will put the script in /etc/cron.hourly/ on Ubuntu which will make it execute once each hour.

What would a good place to store the datafile? The script is run as root.

+2  A: 

/opt and/or /var are typically good places for this. Obviously narrow it down from there.

Jordan S. Jones
+1  A: 

If it's read-only data:

/usr/local/share/program_name

If it's 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 somewhere else. There's also the /opt/XXX school...

viraptor
It's a file I both read and write to from the script. But I never touch it manually.
DeletedAccount
+2  A: 

A subdirectory of /var is the right place for data that will be read and modified by the system. See the Filesystem Hierarchy Standard for more information.

Chas. Owens
Great link to the Filesystem Hierarchy Standard. I've looked at descriptions of it (the hierarchy) but never in such detail.
DeletedAccount
+5  A: 

First, both the datafile and the cron job should be named after your application. Second, if I understand correctly, your data is being changed by the cron job and is not edited by a human. The Filesystem Hierarchy Standard therefore says that if the application is named foo then the cron job should be /etc/cron.hourly/foo and the datafile should be /var/lib/foo. The reason is that the purpose of /var/lib is given as follows:

This hierarchy holds state information pertaining to an application or the system. State information is data that programs modify while they run, and that pertains to one specific host. Users must never need to modify files in /var/lib to configure a package's operation.

Norman Ramsey
Great link to the Filesystem Hierarchy Standard. I've looked at descriptions of it (the hierarchy) but never in such detail. You also had the most informative answer. :-)
DeletedAccount
I couldn't agree more. +1
Jordan S. Jones
A: 

If it's transient data then /tmp or /var/tmp are the standard directories. Persistent data can be placed in any area within the file system that the process can read from and write to. I typically create a "data" directory somewhere in the tree where the process has write permissions such as ~/data, /app/data etc.

ennuikiller
Thanks for your answer! But I think that you can't rely on data being available if you store it in /tmp. It will take one hour between each time I run this script. Or have I misinterpreted something?
DeletedAccount