Cron jobs are tasks scheduled in Linux systems that run automatically at their scheduled times. They need to be included in crontab document. Often beginner administrators wonder whether they need to create a separate crontab for each cron job, and if they can schedule multiple cron jobs in one crontab. In this article, we will learn how to do this.
If you need to schedule cron job, you need to open crontab document using the following command. It will open the crontab document in your default text editor.
$ crontab -e
If you want to change the default text editor of your system, then run the EXPORT editor command and then run above command. Here is an example to set default editor to vi editor.
class="wp-block-preformatted">$ export EDITOR=vi
Once the crontab -e is run, it will open the document in a text editor. Each line will contain a cronjob of the following format.
Now within a crontab file, you can organize each crojob one below the other such that you have one cron job on each line, or you can organize them one after the other on a single line where the cron jobs are separated by semi colon(;), or it can be a combination of both these approaches.
Here is an example to include a different cron job on separate line.
5 * * * * echo 'hello world' 10 * * * * echo 'good morning' 15 * * * * echo 'how are you'
Here is an example to run multiple cron jobs at the same time.
5 * * * * echo 'hello world'; echo 'good morning'; echo 'how are you' OR 5 * * * * echo 'hello world' && echo 'good morning' && echo 'how are you'
In the first example, each cron job runs at a different time while in second example, all cron jobs run at the same time.
While we have learnt how to run multiple cron jobs in a single file, you should also remember that it is possible to have different crontabs for each user on your system, each with a separate list of cronjobs.
In this article, we have learnt how to schedule multiple cron jobs in same crob tab.
Also read:
How to POST JSON Data in Python Requests
How to Remove SSL Certificate & SSH Passphrase
How to Capture Linux Signal in Python
How to Send Signal from Python
How to Clear Canvas for Redrawing in JavaScript
The post How to Schedule Multiple Cron Jobs in One Crontab appeared first on Fedingo.
The latest interim release of Ubuntu introduces “devpacks” for popular frameworks like Spring, along with…
Ubuntu 25.04, codenamed “Plucky Puffin”, is here. This release continues Ubuntu’s proud tradition of integrating…
Ubuntu released its 20.04 (Focal Fossa) release 5 years ago, on March 23, 2020. As…
Focal Fossa will reach the End of Standard Support in May 2025, also known as…
Ubuntu MATE 25.04 is ready to soar! 🪽 Celebrating our 10th anniversary as an official…
Welcome to the Ubuntu Weekly Newsletter, Issue 887 for the week of April 6 –…