Home » Linux » Creating and configuring cron Jobs for task scheduling in Linux

Creating and configuring cron Jobs for task scheduling in Linux

Update on:
Sep 27, 2021

In this article, we are going to learn how to configure Cron Jobs. We are going to use crontab to set up a Cron Job.

Configure Cron

  • Open your terminal and go to the /etc folder and check the /cron folders. You will see the following cron folders:
    • /etc/cron.hourly
    • /etc/cron.daily
    • /etc/cron.weekly
    • /etc/cron.monthly
  • Now, we will copy our shell script into one the preceding folders.
  • If you need to run your shell script to run daily, place it in the cron.daily folder. If you need to run it hourly, place it in the cron.hourly folder, and so on.
  • Example: Write a script and place it in the cron.daily folder. Make the script executable by giving the necessary permissions.
  • Now, run the crontab command:
$ crontab -e
  • Press Enter and it will ask for the editor of your type. By default, it will open vi editor. In my case, I selected nano. Now, create a cron command. The syntax for creating the cron command is:
    • The number of minutes after the hour (0 to 59)
    • The hour in military time (24 hour) format (0 to 23)
    • The day of the month (1 to 31)
    • The month (1 to 12)
    • The day of the week (0 or 7 is Sunday, or use the appropriate name)
    • The command to run
  • If you enter * in all options before the script name, you script will execute, every minute of every hour, of every day of the month, of every month and every day in the week.
  • Now, add the following line in your script:
 * * * * * /etc/name_of_cron_folder/script.sh
  • Save the file and exit.
  • You can list the existing jobs by running the following command:
$ crontab -l
  • To remove the existing Cron Job, delete the line that contains your Cron Job and save it. Run the following command:
$ crontab -e

How it works

We used the crontab command to add and delete the Cron Job. Use the appropriate settings to execute your script daily, hourly, monthly, and weekly.

Related Posts

Creating a lame utility HTTP server in Linux Operating System

In this article, we will discuss the cURL tool in Linux. The cURL tool is used for transferring the data from or to a server. It supports many protocols, and http is one of them. cURL is used to transfer the data from URL. It has so many tricks to offer, such as http...

Finding binary dependencies in Linux Operating System

In this article, we are going to check the executable. We will find out which string is present in it by using the string command.PrerequisitesBesides having a terminal open, make sure you have a binary present in your directory.Find dependencies First, we...

Capturing network traffic headlessly in Linux Operating System

In this article, we are going to learn how to capture traffic. We are going to capture network traffic with a packet sniffer tool called tcpdump. This tool is used to filter or capture TCP/IP packets that are transferred or received over a network.PrerequisitesBesides...

Follow Us

Our Communities

More on Linux

The Ultimate Managed Hosting Platform
Load WordPress Sites in as fast as 37ms!

0 Comments

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

thirteen + fifteen =

Shares