Suppose I am creating two crontab files.

  1. /tmp/my-crontab
  2. /root/my-alternate-crontab

Each crontab file is sheduled to run diffrent scripts.

When I start the cronjob the first is replaced with the older one.

crontab -u smarak /tmp/my-crontab
crontab -u smarak /root/my-alternate-crontab

Is the above possible for a single user ?

  • Why do not have all the commands in one cron? Or use at for single runs? – Romeo Ninov Apr 24 '17 at 11:41
  • Hi Romeo, Thanks for the quick response. Yes it is fine to take the commands in a single file. But just wanted to know why multiple crontab files for a single user is not possible. – SKM Apr 24 '17 at 11:44

No. Each user has one crontab. Why? Because the crontab is the "table" ("tab") of all cron jobs associated with a single user.

If you want to run multiple things with cron, just add multiple lines in your crontab.

If you have multiple files with cron job specifications, just concatenate them:

cat crontab1 crontab2 crontab3 >my-crontab
crontab my-crontab

Two ways to work around having a single crontab.

Put your crontab entries in files in some directory, like ~/crontab.d/thisandthat.cron, then commit any changes from those to the system crontab with:

cat ~/crontab.d/*.cron | crontab -

The extension .cron is to avoid accidentally including backup files from editors. Note that since all the files are concatenated together, any variables set in the files will also apply to files that come later.

You could also do something similar to how /etc/cron.hourly and friends are implemented in Debian. The main /etc/crontab contains rules like this:

17 *    * * *   root    cd / && run-parts --report /etc/cron.hourly

You could arrange for a single crontab entry to run multiple programs. Debian's run-parts dir is similar to for f in dir/* ; do "$f" ; done except that it skips odd filenames, again to avoid running backup files created by editors etc.

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.