Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

I'm using a Linux Enironment (Ubuntu 9.something). I used the following command:

crontab -u myusername /home/myusername/test_cron_file

Works great. When I check the spool folder, everything is as it should be.

Here's the problem. What if I want to use an additional file, let's say for instance, test_cron_file_2? I just want to append that file to the same user. How do I do that?

share|improve this question

migrated from Feb 2 '10 at 1:22

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

why do you want to have 2 such files? what is it that you are wanting to do? – Anonymous Feb 1 '10 at 15:31
Well, it was a test, because I'm doing something with my custom built PHP system. I want to append additional files because the same user www-data will have a number of sites to maintain. I hope I make sense. – willbeeler Feb 1 '10 at 15:32

Try this:

cat /home/myusername/test_cron_file_2 >> /home/myusername/test_cron_file
crontab -u myusername /home/myusername/test_cron_file
share|improve this answer
Thank you. It's like the other answer. I'm trying to do something with a PHP system, that needs to have multiple files being linked under one user. – willbeeler Feb 1 '10 at 15:35

Create a separate file first, then run crontab

cat /home/myusername/test_cron_file /home/myusername/test_cron_file2 > test_cron_file3
crontab -u myusername test_cron_file3
share|improve this answer
I understand what you're doing there, and I like it. However, the problem is a little different. I'm trying to work something out with my PHP system, so that the same user, www-data, can have multiple files, it's looking at. I hope I make sense. – willbeeler Feb 1 '10 at 15:34
cron files are installed with the crontab program, which takes a single file as an argument. Maybe you could do something clever with the -e option, but AFAIK there is no other way to do it. – mobrule Feb 1 '10 at 15:44
ok, I appreciate it – willbeeler Feb 1 '10 at 15:45

cron doesn't want to work with your files. It has a list of entries per user, and you can submit that list of entries to it by editing a file, but it's his list, not yours; and there's not an option to specify multiple lists.

What you want to do constitutes a horrible security risk, but that's already implied when you're working with PHP, so I'll just mention it briefly here and shut up about it.

You can let each of your users edit his/her own file. You assign a file name to each user and give them some access to it so they can edit it. But just as crontab provides the capability to update its table when you do crontab -e, you'll have to provide some functionality to update the crontab list once the user has finished editing his file. You could provide a CGI or PHP script to do this from their browser, if you want.

This script will need to merge all the existing user files into one (cat will mostly take care of this, you only need to make sure each file ends with a newline), and then you can use crontab <file> to update the combined crontab from the latest version of the combined file.

share|improve this answer
I made mention of this, kind of, with my own response. I was on an IRC channel and someone gave me that idea. Thanks a lot though. – willbeeler Feb 1 '10 at 15:51

Well, what I was trying to do was something a bit more complicated involving PHP. However, the two guys who commented are correct. This can't really be done.

To answer my question about PHP, I need to append to the /etc/cron.d/anacron file, every line that I want to show up. That's the easiest explanation that I've found to do what I want.

thanks to all those who answered.

share|improve this answer
You don't really want to append to that file. You are better off using the crontab utility to front-end this for you; it includes at least a little bit of security and error checking. If nothing else, I hope you're at least stopped from doing this by the fact that the file is writeable only to/by root. – Carl Smotricz Feb 1 '10 at 15:58

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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