Categories: TutorialsUbuntu

How to Schedule Multiple Cron Jobs in One Crontab

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.

How to Schedule Multiple Cron Jobs in One Crontab

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.

Sponsored
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.

Sponsored
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.

Ubuntu Server Admin

Recent Posts

How to Install nvidia-smi on Ubuntu or Debian Linux

In this article, we will see how to install nvidia-smi on Ubuntu or Debian Linux.…

8 hours ago

How to Install clang tool on Ubuntu or Debian Linux

In this article, we will see how to install clang tool on Ubuntu or Debian…

1 day ago

How to resolve Ubuntu 20.04 Container Signature Errors on Raspberry Pi ARM Devices

When working with Docker containers on Raspberry Pi devices, you might encounter frustrating signature verification…

2 days ago

How to fix DNS Resolution Issues with OpenVPN on Ubuntu 18.04

You’ve recently upgraded to Ubuntu 18.04 and found that your OpenVPN connection no longer resolves…

2 days ago

How to Fix Ubuntu 18.04 System Monitor Launch Issues

Have you ever tried to open System Monitor on your Ubuntu 18.04 system only to…

3 days ago

What is System Hardening? Essential Checklists from OS to Applications

System hardening means locking down a system and reducing its attack surface: removing unnecessary software…

3 days ago