Creating a crontab

Tutoriel de création d'une tâche planifier sous Linux via l'utilisation de crontab.

Introduction

cron is a program that allows users of Unix systems to automatically run scripts, commands, or software at a pre-specified date and time, or on a pre-defined cycle.

Show crontab

The following command displays the crontab of the current user:

crontab -l

It is also to display the crontabs of all users with the following command:

sudo getent passwd | cut -d: -f1 | perl -e'while(<>){chomp;$l = `crontab -u $_ -l 2>/dev/null`;print "$_\n$l\n" if $l}'

Edit the crontab

The easiest way to create a crontab file is to use the crontab -e command. This command opens the text editor that has been defined for your system environment. The default editor for your system environment is set in the EDITOR environment variable.

The following command modifies the cron table for the current user:

crontab -e

Each line in the crontab represents a task and looks like this:

# ┌───────────── minute (0 - 59)
# │ ┌───────────── heure (0 - 23)
# │ │ ┌───────────── jour du mois (1 - 31)
# │ │ │ ┌───────────── mois (1 - 12)
# │ │ │ │ ┌───────────── jour de la semaine (0 - 6) (Dimanche à samedi;
# │ │ │ │ │                                   7 est aussi le dimanche dans certains systèmes)
# │ │ │ │ │
# │ │ │ │ │
# * * * * * commande à exécuter

# Exemple d'appel à une URL à tous les 15 minutes
*/15 * * * * /usr/bin/curl https://www.webo3.com

Remove the crontab

The following command line deletes the contents, without confirmation, of the crontab for the current user:

crontab -r

Change the default editor

In order to change the default editor to nano you can run the command:

export EDITOR=nano

It is also possible to make this modification permanent by modifying the ~/.bash_profile file

For more information on crontab syntax, see: https://en.wikipedia.org/wiki/Cron

Other suggestions

Commandes Linux utiles

CentOS Linux Ubuntu

Liste de commandes Linux utile tous les jours.

Création d'une crontab

CentOS Linux Ubuntu

Tutoriel de création d'une tâche planifier sous Linux via l'utilisation de crontab.

Extensionner un disque

CentOS Linux Ubuntu

Tutoriel pour extensionner un disque ou partition sous Linux.

Copyright 2017-2020 © webO3 - all rights reserved