Create a Cron Job on Linux CentOS

In this blog post, I will explain and show you how to create your first Cron job on a Linux system.

About Cron

Linux Cron is a task scheduler that allows how to run a routine task that can be automated.

By default, any Linux server can Cron jobs on the following schedule:

  • Hourly
  • Weekly
  • Monthly
  • Daily

We Cron jobs by copying Bash Shell scripts into the Cron system folders which goes by the names above.

Schedules

The Cron schedule folders are located under /etc as shown below:

Create Schedule

Let get going and create Docker script the deploy a container every hour.

I will create a script in the /etc/cron.hourly folder which will run the script every hour.

touch /etc/cron.hourly/docker.sh

I will copy the following line to the script:

#!/bin/bash
docker run -d httpd

We also need to confgire he script to run using the following command.

chmod +x docker.sh

Wait

The Cron job will run the script at the begining of every round hour.

Processing…
Success! You're on the list.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.