Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

is there a way to use multiple crontab files for one user? Thinking something along the lines of crontab file per project instead of crontab per user...

Any help is appreciated...

share|improve this question

migrated from Feb 18 '12 at 3:30

This question came from our site for professional and enthusiast programmers.

It's generally a good idea to maintain your crontab in a separate file anyway, and install it with crontab filename. (I keep my crontab file in a source control system.)

You could have multiple crontab files, and install them all with

cat file1 file2 file3 | crontab

The crontab command normally only manages a single crontab per user. But you can add system crontab files to the /etc/cron.d directory. These files have an extra field after the time specification that indicates the user for the job, and you can have multiple files per user. Even if one of them has a syntax error, the others will still execute.

You'll need root access to install files in that directory.

man 5 crontab for details.

I'm not convinced that circumventing the normal crontab mechanism like this is a good idea, but it should work.

(This assumes the "Vixie Cron" implementation, which is probably what your system uses.)

NOTE: You might be tempted to try

crontab file1 file2 file3 # WRONG

but a quick experiment shows that all file names but the first are silently ignored. The man page says that a single file name is accepted, but doesn't say what happens if multiple file names are provided.

share|improve this answer
I did that today. That would be easy to do, but the goal with this is that each project "manager" would have control over his own crontab. With that approach it would have to be combined like that each time someone changes one of the files, which means they will have to keep track of all the files that need to be compiled – realshadow Feb 18 '12 at 0:22
So create a program (or script, or whatever) to automate it. Note that you can invoke the crontab command from a crontab entry. – Keith Thompson Feb 18 '12 at 0:42
Yes that wouldnt be a problem, but wouldnt that create a small problem? When you combine lets say 10 different files (aka from 10 different people) and one of them has wrong syntax, crontab wont install, but I would have to manually check each file to see who has a syntax error. Unless there is some cron syntax checker... Thats why I was asking if you can have multiple crontabs where cron manages them – realshadow Feb 18 '12 at 10:16
@MateuszKonieczny: That's a good reason, but it's also to easy to erase your crontab accidentally. crontab with no arguments reads a new crontab from stdin. – Keith Thompson Apr 8 at 3:40
@MateuszKonieczny: No, I just keep it in a CVS repo and copoy it to $HOME when I update it. (I use CVS because Git didn't exist when I started doing this.) – Keith Thompson Apr 8 at 15:53

Why would you do that? You could use multiple lines in crontab - I think that would do the job too.

There are also the directories you could probably use:

share|improve this answer
Thats how it is now :) I just would like to know if there is a way to do this – realshadow Feb 17 '12 at 22:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .