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.

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

Ubuntu Server Admin

Recent Posts

🚀 Deploy Elastic Stack on Ubuntu VPS (5 Minute Quick-Start Guide)

Here’s the guide to deploy Elastic Stack on Ubuntu VPS, with secure access, HTTPS proxying,…

1 day ago

🚀 Deploy Nagios on Ubuntu VPS

This guide walks through deploying Nagios Core on an Ubuntu VPS, from system prep to…

1 day ago

Shoryuken Has a New Maintainer, and v7.0.0 Is Almost There

After a decade under Pablo Cantero's stewardship, Shoryuken has a new maintainer - me. I'm…

5 days ago

A better way to provision NVIDIA BlueField DPUs at scale with MAAS

MAAS 3.7 has been officially released and it includes a bunch of cool new features.…

2 weeks ago

Ruby Floats: When 2.6x Faster Is Actually Slower (and Then Faster Again)

Update: This article originally concluded that Eisel-Lemire wasn't worth it for Ruby. I was wrong.…

2 weeks ago

MicroCeph: why it’s the superior MinIO alternative (and how to use it)

Recently, the team at MinIO moved the open source project into maintenance mode and will…

2 weeks ago