For those who are familiar with the Unix system, you will also be familiar with the cron application that allows you to schedule and automate tasks to run on their own. We even have tutorials that show you how to get started with cron and crontabs. However, cron is not perfect, as it requires your system to be running 24 hours a day. If you have a habit of turning off your computer at night, and a cron job is scheduled in the sleeping hours, the task won’t be executed. Luckily, there are several cron alternatives that can do a better job than cron. Let’s check them out.
Anacron is a periodic command scheduler just like cron. The only difference is that it does not need your computer to be always running. You can schedule your task to run at any time. When your computer is off, the task will be executed the next time you turn the computer on.
To get started, simply install
anacron in your system. It is available in most package managers. Use the following command to install in Ubuntu:
Anacron works similar to cron. You can add your job to the
The syntax to add a job is
For example, to run a backup script everyday, you can add the following command:
The disadvantage of anacron is that it only deals with tasks on a daily, weekly or monthly schedule. You can’t use it for a hourly or minutes schedule.
Another brilliant cron alternative that you can install today is Cronie. Unlike the previous entries, Cronie is a small suite of software that aims to provide a complete cron experience. In order to do that, Cronie includes the anacron package by default. This means that cronie can provide both synchronous and asynchronous job scheduling out of the box.
Further, installing cronie is relatively straightforward. First, you need to obtain the program’s source code from their Github page:
Once done, unpack the archive by running tar on the terminal:
From there, go inside the Cronie directory and compile the program’s source code:
Once done, you can now use Cronie to manage the cron jobs in your machine. Similar to anacron and cron, you can create a cron job by running
crontab -e. This will allow you to edit your specific user’s crontab. Knowing that, Cronie also follows the standard format:
Fcron is the best of both cron and anacron. It doesn’t require your computer to be running 24×7, and it can work with tasks on an hourly or minute basis.
The only way to install Fcron is to download the source file and compile it yourself.
- Download the source file here.
- Extract the archive. Open a terminal and change the filepath to the extracted archive folder.
- Run the following commands:
It will ask you a few questions during the installation and you can safely answer “y” (yes) for all of them.
To start creating a fcron job, simply type
fcron -e in the terminal.
The syntax for fcron is similar to cron:
and it comes with more options than cron, such as setting up a task to run between a time range.
For those who prefer a GUI, you can check out fcronq
Bcron is a simple and modern alternative to the standard cron program. Similar to Cronie, bcron aims to provide a suite of software that manages your system’s job scheduling. It does this by separating all of the component functions of cron into their own respective programs. This, in turn, allows bcron to be both highly modular and secure.
With that, installing bcron is incredibly easy. In that, if you are using Debian or Ubuntu you can install the program through apt:
Once done, you can now use bcron to schedule tasks in your system. In order to do that, you need to first run the following command to enable the program:
The first command will start bcron in your system while the second one will tell bcron to open and update both the crontab and cron.d files. From there, the syntax of creating a new task is similar to both anacron and cronie. For example, I can write the following line to tell bcron to run my script every 5 AM on the 1st of every month:
Hcron is relatively unknown, but that does not make it less useful. In fact, it comes with several features that make it unique. For example, you can easily label and organize your cron type jobs, manage a network of computers and your users’ crontab files, beck up easily, and version control your cron type jobs.
To install hcron, download the .deb file (or .rpm file, depending on your Linux system) and install it in your system.
Hcron stores each event as a plain text file. To get started, simply create a text file with the command:
In the text editor that opens, you can fill in the details of the event.
There are many more things that you can do with hcron and it is advisable to download the user guide to have a better understanding of how it works.
Jobber is a task scheduler written in GO and is a more powerful tool than cron. It features job execution history with status, controlling whether and when a job is run again after it fails and getting notified on each failed run or only about jobs that were disabled due to repeated failures.
To install Jobber, you have to make sure that GO is installed in your system. Next, type the commands:
After the installation, start Jobber with the command:
To create jobs, create a file named “.jobber” in your home directory and add the job in the following format:
As you can see from the format, it allows you to define the actions to take when it has errors (“Stop”, “Backoff” or “Continue”) and whether it should notify you when it fails.
Once you have updated the job list, use
jobber reload to get Jobber to reload the new list.
At any time, you can use
jobber log to see a list of recent runs of any jobs.
Mcron is a fast and innovative task scheduling program for Linux. Similar to the programs above, mcron aims to provide you with a simple way to manage the scripts and programs that you want to run in your system. Unlike the programs above, mcron also aims to redefine task scheduling by reconstructing cron jobs from scratch.
With that, installing mcron is incredibly simple. It is available in both Debian and Ubuntu and you can easily obtain it by running the following:
Once done, you can now start using mcron as your scheduler. To do that, you need to first create the directory where mcron will look for its tasks:
From there, you can now edit this cron file to contain all of the jobs that you want mcron to do. Unlike the programs above, mcron uses an alternative syntax for scheduling:
jobfunction tells mcron that this line of Lisp contains a task that it needs to schedule.
rangeare lists that hold the timing information for mcron. In that, the type controls the scale that mcron will operate on while the range determines the time interval for that scale.
- Lastly, the
commandis a string that tells mcron which command or program it needs to run.
With that, I can then write the following to my .config/cron file to run my script once an hour for three hours a day:
Frequently Asked Questions
Is it possible to use the regular cron syntax with mcron?
Aside from being an innovative task scheduler, mcron also aims to be backwards compatible to the older cron syntax. As such, you can also use a crontab-like syntax for your .config/cron file. For example, I can write the following line to tell mcron that I want to run my script once a day by midnight:
One important thing to note, however, is that writing your scheduled tasks this way will not allow you to use mcron’s more extensive and flexible features.
Is it possible to stop cron from sending mail to my user account?
It is possible to stop cron from sending any system mail to your user. In order to do that, you will need to edit your crontab and provide a
MAILTO variable with a value of
nobody. For example, this is an excerpt of a crontab where I have disabled the system mail:
Knowing that, you can also use this syntax to redirect another user’s crontab output to a different user. For example, you can easily set this variable on the root user’s crontab to get the output from all of the scheduled tasks that it is running.
Which is the best cron alternative for me?
While this is a highly subjective question, a good cron alternative should be able to do everything that you might need for your specific use case. For example, you might want to consider using simpler task schedulers such as anacron and cronie if you only plan to use cron for the occasional basic task.
On the other hand, a more flexible and powerful task scheduler such as mcron will allow you to script and define the behavior of cron itself. However, using mcron for even basic tasks can be daunting for the uninitiated beginner.
Image credit: Unsplash
Our latest tutorials delivered straight to your inbox