I am using crontab to ring a bell in a specific time & date. Sometimes I need to set one schedule and sometimes the other. My plan is to create 2 different crontab files:

1.) The Original Crontab File. This crontab file will ring a bell in every 1 hr & 30mins from Mondays through Fridays.
2.) Another Crontab File with a different name which rings the bell in every 2 hrs from Mondays through Fidays.

How can I set which crontab file is to use and which one isn't?

1 Answer 1


Why do you need 2 different crontabs (it’s not possible on user level, only on system level in /etc/cron.d - there in separate files you can specify the user which runs the cron)? Simply make 2 lines in one crontab each with a different schedule. Or a different command/script to execute, which will check your condition and decide whether to run some commands or not.

See further discussion about maintaining separate files and installing them into your (one) crontab here: https://superuser.com/questions/391246/multiple-crontabs-for-one-user

Basically (pseudo-code) doing this:

if <something> cat file1 | crontab; else <something-else> cat file2 | crontab; fi

which anyways will have to run on a cron. So my previous suggestion is more elegant in that sense.

  • Well, the 1 hr & 30mins and 2 hrs are just there to shorten my question. The real schedule is a little bit more complicated than that. It has 7-9 lines and sometimes I may need to switch it with another schedule (which the times are really different from the MAIN schedule and is saved in a different crontab) but the problem is I don't know how to switch from 1 crontab to another.
    – IT Help
    Nov 5, 2020 at 3:45
  • You can do as I told you, just switch the contents of the same crontab: cat file1 | crontab and cat file2 | crontab Nov 5, 2020 at 5:29
  • 2
    @GeorgeMogilevsky Just crontab file would load the given file as the crontab schedule, without the need for cat.
    – Kusalananda
    Nov 5, 2020 at 7:31
  • I was just quoting the other answer.. Nov 5, 2020 at 14:26

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.