How to Set Up a Cron Job in Linux? – cron job example

A cron job is a Linux utility that allows you to schedule scripts or other commands to run automatically at specified intervals. Here’s how to set up a cron job in Linux:

  1. Open a terminal window and type the following command to edit the crontab file:
crontab -e

2. In the file, each line represents a separate cron job. The syntax of each line is as follows:

* * * * * [command to run]

3. Each field represents a different aspect of the scheduling, from left to right:

  • Minutes (0-59)
  • Hours (0-23)
  • Days of the month (1-31)
  • Months (1-12)
  • Days of the week (0-7, where both 0 and 7 represent Sunday)

4. For example, the following line will run the command /usr/bin/example.sh every day at 10 PM:

0 22 * * * /usr/bin/example.sh

5. Save the file and exit the editor. Your new cron job will be active and will run at the specified intervals.

Note: To view a list of your current cron jobs, type the following command:

crontab -l

And to remove a cron job, simply delete the corresponding line from the crontab file and save the changes.

Leave a Comment