13

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...

13

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.

| 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
  • 1
    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
  • 1
    @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 '16 at 3:40
  • 1
    @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 '16 at 15:53
  • 1
    @KeithThompson Oh, gotcha! I'm creating a document to help people run Fedora Core 24 from "scratch" without evolution or gnome: github.com/barrycarter/bcapps/blob/master/FEDORA and wanted to share part of my cron file but not all of it. Your solution (creating bc-public-cron in the GIT directory and bc-private-cron outside of it) fits the bill nicely. – user59328 Nov 17 '16 at 18:23
4

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:

cron.d/
cron.daily/
cron.hourly/
cron.monthly/
cron.weekly/
| 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.