How to Create a Crontab to Run on the First of the Month?

8

Cron is an extremely useful Linux utility that is extensively used to schedule different tasks at a specified time. This provides a high level of control and automation for performing different jobs with minimal human intervention. In today’s article, we will demonstrate how to create a Crontab to run on the first of the month in Linux Mint 20.

Method of Creating a Crontab to Run on the First of the Month in Linux Mint 20

For creating a Crontab to run on the first of the month in Linux Mint 20, you will have to follow the steps stated below:

Step 1: Create a Sample Cron Job to Run on the First of the Month in Linux Mint 20
First, you need to create a sample Cron job you want to run in the first month. However, this step is optional as you can even attempt to run a single command at the desired schedule, i.e., you do not necessarily need to create a program or a script. For demonstration, we have simply created a Bash file in the Home directory named Month.sh. Whenever this script is executed, it will display a simple message on the terminal. The contents of our Bash script are shown in the following image. This Bash script will act as our sample Cron job.

Step 2: Start the Cron Daemon on your Linux Mint 20 System
Once a sample Cron job has been created, you need to start the Cron daemon in the background of your Linux Mint 20 system. You can do this by executing the command shown below in your terminal:

$ sudo systemctl start cron

This command will simply start the Cron daemon without displaying any messages on the terminal.

Step 3: Ensure the Active Status of the Cron Daemon on your Linux Mint 20 System
After that, you need to ensure that the Cron daemon is active and running. This status can be checked by executing the following command in the Linux Mint 20 terminal:

$ sudo systemctl status cron

If the status of your Cron daemon is “active (running),” as highlighted in the image shown below, then you can conveniently proceed to the next step.

Step 4: Add the Desired Cron Job to the Crontab File for its Execution on the First of the Month in Linux Mint 20
Finally, you can add the sample Cron job to the Crontab file for its execution on the first of the month. For that, you first need to access the Crontab file with the following command:

The Crontab file is shown in the image below:

Now, you need to add the following statement to your Crontab file for the execution of your sample Cron job on the first of the month:

* * 1 * * PathToYourSampleCronJob

Here, it would be best if you replaced PathToYourSampleCronJob with the actual path of the sample Cron job that you have created. In our case, it was /home/kbuzdar/Month.sh.

When you save your Crontab file after adding this statement to it, the Cron daemon will automatically install the new Crontab, as shown in the image below. It means that now your sample Cron job is all set to be executed on the first of the month.

Conclusion

Following the procedure prescribed in this article, you will create a Crontab to run on the first of the month. You can also attempt to execute a specific command on the first of the month instead of running a script by following the very same method.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More