How to Schedule a Crontab Job for Every Hour?

In Linux, the “cron” daemon or the “cron job” is a time-based job used to automate any task/set of commands at the specified time interval. Basically, it is a software tool that schedules jobs periodically at a fixed time, day, date, or interval.

This post will demonstrate how to schedule a crontab job for every hour.

Prerequisites: Cron Service is Active

It is recommended to check the “crontab” service before scheduling the “Extra.sh” script as a  cron job for every hour. To perform this task, use the “systemctl status” command in this way:

$ sudo systemctl status cron

The highlighted section verifies that the crontab service is in an “active (running)” state.To exit from this section, press the “q” tab.

Tip: Start the Crontab Service (If Inactive)

If the “crontab” service is not active, then use the “systemctl start” command to start it:

$ sudo systemctl start cron

How do Create and Schedule a Crontab Job for Every Hour?

The crontab file assists the user in scheduling the crontab job for every hour. To perform this task, follow the step-by-step guidelines that are mentioned below.

Step 1: Create a Task (To be Run as a Cron Job)

First, create a cron job to schedule every hour. In this scenario, the “Extra.sh” script is created in the default “nano” text editor:

$ nano Extra.sh

The “Extra.sh” holds an “echo” command that will print the line as shown below screenshot:

Change the “Extra.sh” permissions by using the “chmod” command and make it executable:

$ chmod +x Extra.sh

Step 2: Open the Crontab Tab File

The “crontab” file can be easily created or modified with the help of the below command:

$ crontab -e

Select the first “/bin/nano” editor by typing “1” for the creation of the new crontab “/tmp/crontab.mdqw6h/crontab” file:

Step 3: Add the Cron Job Into the Crontab File

Now, add the below-mentioned line to the newly created crontab file to schedule the “Extra.sh” script as a crontab job:

0 * * * * /home/itslinuxfoss/test/Extra.sh

The above line is divided into two major parts:

  • 0 * * * *”:  Parameter’ refers to the cron daemon for the execution of “Extra.sh” cron job for every hour.
  • path: Identifies the absolute path of the “Extra.sh” script.

Save(CTRL+S) and exit(CTRL+X) the editor.

Step 4: Installing the New Crontab Job

After that, check the crontab job “Extra.sh” file status that is now changed as shown in the below screenshot:

$ crontab -e

Hence, after every hour when the user will run the “Extra.sh” script on the terminal then its content will display as an output.

It is all about scheduling a crontab job for every hour.

Conclusion

To schedule a crontab job every hour, the user must create a cron job (probably a Linux command or a bash script) and put it in the crontab file. Create or modify the “crontab” file via the “crontab -e” command. Once the cron job is added, then it will be executed after every hour. This post briefly explained the process to run a cron job every minute in Linux.