Linux Scheduling

Set up a cron job

Price range: €16.43 through €20.33

Command:

To edit the cron jobs, use the crontab command:

bash
crontab -e

Explanation:

  • crontab -e: Opens the current user’s crontab file in the default text editor, allowing you to edit or add new cron jobs.

Cron Syntax:

A cron job is defined using the following syntax:

lua
* * * * * /path/to/your/command
- - - - -
| | | | |
| | | | +-- Day of the week (0 - 6) (Sunday=0)
| | | +---- Month (1 - 12)
| | +------ Day of the month (1 - 31)
| +-------- Hour (0 - 23)
+---------- Minute (0 - 59)

Example Cron Job:

If you want to run a script (/path/to/your/script.sh) every day at 3:30 AM, the cron job entry would be:

bash
30 3 * * * /path/to/your/script.sh
  • 30: Minute field (the 30th minute)
  • 3: Hour field (at 3 AM)
  • *: Day of the month field (every day)
  • *: Month field (every month)
  • *: Day of the week field (every day of the week)

Additional Time Intervals:

  • Every 5 minutes:
    bash
    */5 * * * * /path/to/your/script.sh
  • Every Monday at 12:00 PM:
    bash
    0 12 * * 1 /path/to/your/script.sh

    (1 represents Monday in the day-of-week field)

  • Every 1st of the month at 4:00 PM:
    bash
    0 16 1 * * /path/to/your/script.sh

Result:

After saving the cron job in the crontab file, the system will automatically run the specified script or command at the designated time intervals.


Additional Notes:

  • To list all existing cron jobs for the current user, use:
    bash
    crontab -l
  • To remove all cron jobs, use:
    bash
    crontab -r
Select options This product has multiple variants. The options may be chosen on the product page