forked from Fascinated/docs
69 lines
1.1 KiB
Markdown
69 lines
1.1 KiB
Markdown
---
|
|
title: How to use cronjobs
|
|
description: Examples on how to use cronjob to automate tasks
|
|
published: true
|
|
date: 2023-06-27T08:28:13.676Z
|
|
tags:
|
|
editor: markdown
|
|
dateCreated: 2023-06-27T08:28:13.676Z
|
|
---
|
|
|
|
# How to use cronjobs
|
|
|
|
This guide provides examples on how to use cronjob to automate tasks.
|
|
|
|
## Get Started
|
|
|
|
- Begin by opening a terminal and running the following command:
|
|
|
|
```bash
|
|
crontab -e
|
|
```
|
|
|
|
This command will open the crontab file in the nano text editor.
|
|
|
|
- Next, you need to define the cronjob. Add the following lines to the file:
|
|
|
|
```bash
|
|
* * * * * <command>
|
|
```
|
|
|
|
- Finally, you can save the file by pressing `Ctrl + X` and then `Y`.
|
|
|
|
## Syntax
|
|
|
|
```bash
|
|
* <- minute (0-59)
|
|
* <- hour (0-23)
|
|
* <- day of month (1-31)
|
|
* <- month (1-12)
|
|
* <- day of week (0-6) (Sunday=0)
|
|
<command>
|
|
```
|
|
|
|
## Examples
|
|
|
|
### Run a command every minute
|
|
|
|
```bash
|
|
* * * * * <command>
|
|
```
|
|
|
|
### Run a command every 5 minutes
|
|
|
|
```bash
|
|
*/5 * * * * <command>
|
|
```
|
|
|
|
### Run a command every hour
|
|
|
|
```bash
|
|
0 * * * * <command>
|
|
```
|
|
|
|
### Run a command every day at midnight
|
|
|
|
```bash
|
|
0 0 * * * <command>
|
|
```
|