Différences
Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédente | ||
elearning:workbooks:debian:10:junior:l110 [2022/05/17 08:16] – created admin | elearning:workbooks:debian:10:junior:l110 [2024/03/08 08:35] (Version actuelle) – admin | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
~~PDF: | ~~PDF: | ||
- | Version : **2022.01** | + | Version : **2024.01** |
Dernière mise-à-jour : ~~LASTMOD~~ | Dernière mise-à-jour : ~~LASTMOD~~ | ||
- | ======LCF505 | + | ======LDF505 |
=====Contenu du Module===== | =====Contenu du Module===== | ||
- | * **LCF505 | + | * **LDF505 |
* Contenu du Module | * Contenu du Module | ||
* LAB #1 - cron | * LAB #1 - cron | ||
Ligne 15: | Ligne 15: | ||
* 1.2 - Les Champs Temporels | * 1.2 - Les Champs Temporels | ||
* 1.3 - Les crontabs Utilisateurs | * 1.3 - Les crontabs Utilisateurs | ||
+ | * 1.4 - Les Fichiers / | ||
* LAB #2 - anacron | * LAB #2 - anacron | ||
* 2.1 - Le Fichier / | * 2.1 - Le Fichier / | ||
- | * 2.2 - Les Champs Temporels | + | * 2.2 - Les Fichiers |
- | * 2.3 - Le Fichier / | + | |
* LAB #3 - at | * LAB #3 - at | ||
- | * 3.1 - Le Répertoire /var/spool/at/ | + | * 3.1 - Les Fichiers / |
+ | * 3.2 - Le Répertoire /var/spool/cron/atjobs | ||
- | =====cron===== | + | =====LAB #1 - cron===== |
- | <WRAP center round important | + | Le service crond est normalement lancé au démarrage de la machine. Ce service est chargé de faire exécuter des tâches ( commandes et scripts ) à des moments précis. |
- | **Important** | + | |
+ | <WRAP center round important | ||
+ | **Important** | ||
</ | </ | ||
- | |||
- | Le service crond est normalement lancé au démarrage de la machine. Ce service est chargé de faire exécuter des tâches ( commandes et scripts ) à des moments précis. Le service crond présume que la machine est allumée en permanence. | ||
Le service crond lit toutes les minutes le fichier **/ | Le service crond lit toutes les minutes le fichier **/ | ||
Ligne 36: | Ligne 37: | ||
L' | L' | ||
- | Sous RHEL/ | + | Les crontabs des utilisateurs ont comme nom, le nom de l' |
====1.1 - Le Fichier / | ====1.1 - Le Fichier / | ||
- | Sous RHEL/CentOS le fichier | + | Sous Debian 11 **/ |
< | < | ||
- | [root@centos8 | + | root@debian11:~# cat / |
- | SHELL=/bin/bash | + | # /etc/crontab: system-wide crontab |
- | PATH=/sbin:/bin:/ | + | # Unlike any other crontab you don't have to run the `crontab' |
- | MAILTO=root | + | # command to install the new version when you edit this file |
+ | # and files in /etc/cron.d. These files also have username fields, | ||
+ | # that none of the other crontabs do. | ||
- | # For details see man 4 crontabs | + | SHELL=/ |
+ | PATH=/ | ||
# Example of job definition: | # Example of job definition: | ||
Ligne 57: | Ligne 61: | ||
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun, | # | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun, | ||
# | | | | | | # | | | | | | ||
- | # * * * * * user-name | + | # * * * * * user-name command to be executed |
+ | 17 * * * * | ||
+ | 25 6 * * * | ||
+ | 47 6 * * 7 | ||
+ | 52 6 1 * * | ||
+ | # | ||
</ | </ | ||
- | <WRAP center round important | + | <WRAP center round important |
- | **Important** | + | **Important** |
</ | </ | ||
Ligne 83: | Ligne 92: | ||
| Le joker * | Dans le champs minutes = toutes les minutes | | | Le joker * | Dans le champs minutes = toutes les minutes | | ||
| Une périodicité telle 0-23/2 | Dans le champs heures = toutes les deux heures | | | Une périodicité telle 0-23/2 | Dans le champs heures = toutes les deux heures | | ||
- | |||
- | Par exemple, voici le fichier **/ | ||
- | |||
- | < | ||
- | [root@centos8 ~]# cat / | ||
- | # Run the hourly jobs | ||
- | SHELL=/ | ||
- | PATH=/ | ||
- | MAILTO=root | ||
- | 01 * * * * root run-parts / | ||
- | </ | ||
====1.3 - Les crontabs Utilisateurs==== | ====1.3 - Les crontabs Utilisateurs==== | ||
- | Chaque utilisateur peut avoir sa propre version d'un fichier crontab. Pour vérifier s'il existe une version de crontab pour lui, l' | + | Chaque utilisateur peut avoir sa propre version d'un fichier crontab. Pour vérifier s'il existe une version de crontab pour lui, l' |
< | < | ||
- | [root@centos8 | + | root@debian11:~# exit |
logout | logout | ||
- | [trainee@centos8 | + | trainee@debian11:~$ crontab -l |
no crontab for trainee | no crontab for trainee | ||
</ | </ | ||
Ligne 109: | Ligne 107: | ||
< | < | ||
- | [trainee@centos8 | + | trainee@debian11:~$ crontab -e |
- | </ | + | </ |
Cette commande lance l' | Cette commande lance l' | ||
Ligne 123: | Ligne 121: | ||
< | < | ||
- | [trainee@centos8 | + | trainee@debian11:~$ crontab -e |
no crontab for trainee - using an empty one | no crontab for trainee - using an empty one | ||
+ | |||
+ | Select an editor. | ||
+ | 1. / | ||
+ | 2. / | ||
+ | |||
+ | Choose 1-2 [1]: 2 | ||
crontab: installing new crontab | crontab: installing new crontab | ||
</ | </ | ||
- | <WRAP center round important | + | <WRAP center round important |
**Important** : Ce fichier crontab va être exécuté toutes les minutes. La commande va inscrire le répertoire courant dans le fichier pwd.txt. | **Important** : Ce fichier crontab va être exécuté toutes les minutes. La commande va inscrire le répertoire courant dans le fichier pwd.txt. | ||
</ | </ | ||
- | Le fichier crontab que vous venez de créer, au nom de votre utilisateur, | + | Le fichier crontab que vous venez de créer, au nom de votre utilisateur, |
Malgré le fait que vous venez de l' | Malgré le fait que vous venez de l' | ||
Ligne 139: | Ligne 143: | ||
< | < | ||
- | [trainee@centos8 | + | trainee@debian11:~$ cat / |
+ | cat: / | ||
+ | |||
+ | trainee@debian11: | ||
Password: fenestros | Password: fenestros | ||
- | [root@centos8 | + | |
+ | root@debian11:~# cat / | ||
+ | # DO NOT EDIT THIS FILE - edit the master and reinstall. | ||
+ | # (/ | ||
+ | # (Cron version -- $Id: crontab.c,v 2.13 1994/01/17 03:20:37 vixie Exp $) | ||
+ | # Edit this file to introduce tasks to be run by cron. | ||
+ | # | ||
+ | # Each task to run has to be defined through a single line | ||
+ | # indicating with different fields when the task will be run | ||
+ | # and what command to run for the task | ||
+ | # | ||
+ | # To define the time you can provide concrete values for | ||
+ | # minute (m), hour (h), day of month (dom), month (mon), | ||
+ | # and day of week (dow) or use ' | ||
+ | # | ||
+ | # Notice that tasks will be started based on the cron's system | ||
+ | # daemon' | ||
+ | # | ||
+ | # Output of the crontab jobs (including errors) is sent through | ||
+ | # email to the user the crontab file belongs to (unless redirected). | ||
+ | # | ||
+ | # For example, you can run a backup of all your user accounts | ||
+ | # at 5 a.m every week with: | ||
+ | # 0 5 * * 1 tar -zcf / | ||
+ | # | ||
+ | # For more information see the manual pages of crontab(5) and cron(8) | ||
+ | # | ||
+ | # m h dom mon dow | ||
* * * * * /bin/pwd > pwd.txt | * * * * * /bin/pwd > pwd.txt | ||
</ | </ | ||
+ | |||
+ | ====1.4 - Les Fichiers / | ||
Afin d' | Afin d' | ||
Ligne 156: | Ligne 192: | ||
L' | L' | ||
- | Il existe un alternatif très efficace pour des machines qui ne sont pas constamment allumée. Cette solution est le logiciel Anacron. Sous RHEL/ | + | Il existe un alternatif très efficace pour des machines qui ne sont pas constamment allumée. Cette solution est le logiciel Anacron. |
- | ====2.1 - Le Fichier / | + | Ouvrez le fichier / |
- | + | ||
- | Ouvrez | + | |
< | < | ||
- | [root@centos8 | + | root@debian11:~# cat / |
# / | # / | ||
Ligne 169: | Ligne 203: | ||
SHELL=/ | SHELL=/ | ||
- | PATH=/ | + | PATH=/ |
- | MAILTO=root | + | HOME=/root |
- | # the maximal random delay added to the base delay of the jobs | + | LOGNAME=root |
- | RANDOM_DELAY=45 | + | |
- | # the jobs will be started during the following hours only | + | |
- | START_HOURS_RANGE=3-22 | + | |
- | #period in days delay in minutes | + | # These replace cron's entries |
- | 1 5 cron.daily nice run-parts / | + | 1 |
- | 7 25 cron.weekly nice run-parts / | + | 7 10 |
- | @monthly | + | @monthly |
</ | </ | ||
- | Vous noterez que ce fichier fait référence aux répertoires **/etc/cron.daily**, **/etc/cron.weekly** et **/ | + | ====2.1 - Le Fichier |
- | ====2.2 - Les Champs Temporels==== | + | Vous noterez que ce fichier fait référence aux répertoires cron.daily, cron.weekly et cron.monthly. |
Les deux premiers champs sont des champs temporels. Dans le cas d' | Les deux premiers champs sont des champs temporels. Dans le cas d' | ||
^ Période ^ Délai ^ | ^ Période ^ Délai ^ | ||
- | | La périodicité en jours | Le délai en minutes, après le **démarrage d' | + | | La périodicité en jours | Le délai en minutes, après le démarrage d' |
+ | |||
+ | ====2.2 - Les Fichiers cron.daily, cron.weekly et cron.monthly==== | ||
Anacron mémorise dans les fichiers qui se trouvent dans **/ | Anacron mémorise dans les fichiers qui se trouvent dans **/ | ||
< | < | ||
- | [root@centos8 | + | root@debian11:~# ls / |
cron.daily | cron.daily | ||
- | [root@centos8 | + | root@debian11:~# cat / |
- | 20210602 | + | 20220606 |
- | [root@centos8 | + | root@debian11:~# cat / |
- | 20210602 | + | 20220531 |
- | [root@centos8 | + | root@debian11:~# cat / |
- | 20210526 | + | 20220510 |
</ | </ | ||
- | ====2.3 | + | Si cron exécute les tâches normalement, |
- | Sous RHEL/CentOS, anacron consulte le fichier | + | Sous Debian 11, il existe trois fichiers |
- | Voici le script **/etc/cron.hourly/0anacron** : | + | < |
+ | root@debian11: | ||
+ | root@debian11: | ||
+ | /etc/cron.daily/0anacron | ||
+ | / | ||
+ | / | ||
+ | </ | ||
+ | |||
+ | A savoir | ||
< | < | ||
- | [root@centos8 | + | root@debian11:~# cat /etc/cron.daily/0anacron |
#!/bin/sh | #!/bin/sh | ||
- | # Check whether 0anacron was run today already | + | # |
- | if test -r /var/spool/anacron/cron.daily; then | + | # anacron' |
- | | + | # |
- | fi | + | # This script updates anacron time stamps. It is called through run-parts |
- | if [ `date +%Y%m%d` = "$day" | + | # either by anacron |
- | exit 0 | + | # |
- | fi | + | # The script is called |
+ | # _before_ all other scripts. | ||
- | # Do not run jobs when on battery power | + | test -x /usr/sbin/anacron || exit 0 |
- | online=1 | + | anacron -u cron.daily |
- | for psupply in AC ADP0 ; do | + | |
- | sysfile=" | + | |
- | if [ -f $sysfile ] ; then | + | root@debian11: |
- | if [ `cat $sysfile 2>/dev/null`x = 1x ]; then | + | #!/bin/sh |
- | | + | # |
- | break | + | # anacron' |
- | else | + | # |
- | | + | # This script updates anacron time stamps. It is called through run-parts |
- | fi | + | # either by anacron itself or by cron. |
- | fi | + | # |
- | done | + | # The script is called " |
- | if [ $online = 0 ]; then | + | # _before_ all other scripts. |
- | exit 0 | + | |
- | fi | + | test -x / |
- | / | + | anacron -u cron.weekly |
+ | |||
+ | root@debian11: | ||
+ | #!/bin/sh | ||
+ | # | ||
+ | # anacron' | ||
+ | # | ||
+ | # This script updates anacron time stamps. It is called through run-parts | ||
+ | # either by anacron itself or by cron. | ||
+ | # | ||
+ | # The script is called " | ||
+ | # _before_ all other scripts. | ||
+ | |||
+ | test -x /usr/sbin/anacron || exit 0 | ||
+ | anacron -u cron.monthly | ||
</ | </ | ||
- | Ce script a pour but d' | + | Le but de ces trois scripts est de mettre à jour la date inscrite dans les trois fichiers |
=====LAB #3 - at===== | =====LAB #3 - at===== | ||
- | Tout comme avec la commande cron, root a la possibilité d' | + | Sous Debian 11, la commande **at** n'est pas installée par défaut : |
+ | |||
+ | < | ||
+ | root@debian11: | ||
+ | |||
+ | root@debian11: | ||
+ | |||
+ | root@debian11: | ||
+ | / | ||
+ | </ | ||
+ | |||
+ | ====3.1 - Les Fichiers / | ||
+ | |||
+ | Tout comme avec la commande cron, root a la possibilité d' | ||
* **/ | * **/ | ||
* **/ | * **/ | ||
- | Si le fichier at.allow existe, seuls les utilisateurs dans ce fichier pourront exécuter at. | + | < |
+ | root@debian11: | ||
+ | cat: / | ||
+ | |||
+ | root@debian11: | ||
+ | alias | ||
+ | backup | ||
+ | bin | ||
+ | daemon | ||
+ | ftp | ||
+ | games | ||
+ | gnats | ||
+ | guest | ||
+ | irc | ||
+ | lp | ||
+ | |||
+ | man | ||
+ | nobody | ||
+ | operator | ||
+ | proxy | ||
+ | qmaild | ||
+ | qmaill | ||
+ | qmailp | ||
+ | qmailq | ||
+ | qmailr | ||
+ | qmails | ||
+ | sync | ||
+ | sys | ||
+ | www-data | ||
+ | </ | ||
+ | |||
+ | <WRAP center round important 50%> | ||
+ | **Important** - Si le fichier | ||
+ | </ | ||
+ | |||
+ | ====3.2 - Le Répertoire / | ||
- | En tant que root, mettez en place maintenant deux tâches pour le 31/12/2042 à 13h00 et 14h00 respectivement : | + | En tant que root, mettez en place maintenant deux tâches pour le 31/12/2018 à 13h00 et 14h00 respectivement : |
< | < | ||
- | [root@centos8 | + | root@debian11:~# at 13:00 12/31/2042 |
warning: commands will be executed using /bin/sh | warning: commands will be executed using /bin/sh | ||
at> pwd > / | at> pwd > / | ||
+ | [^D] <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | ||
at> <EOT> | at> <EOT> | ||
job 1 at Wed Dec 31 13:00:00 2042 | job 1 at Wed Dec 31 13:00:00 2042 | ||
- | [root@centos8 | + | root@debian11:~# at 14:00 12/31/2042 |
warning: commands will be executed using /bin/sh | warning: commands will be executed using /bin/sh | ||
at> free > / | at> free > / | ||
+ | [^D] <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | ||
at> <EOT> | at> <EOT> | ||
job 2 at Wed Dec 31 14:00:00 2042 | job 2 at Wed Dec 31 14:00:00 2042 | ||
</ | </ | ||
- | ====3.1 - Le Répertoire / | + | Sous Debian 11, les fichiers concernant ces deux tâches sont stockés dans le répertoire **/ |
- | + | ||
- | Sous RHEL/CentOS, les fichiers concernant ces deux tâches sont stockés dans le répertoire **/ | + | |
< | < | ||
- | [root@centos8 | + | root@debian11:~# ls /var/spool/cron/atjobs |
- | a000010249d9f8 | + | a000010249d890 |
</ | </ | ||
- | A l' | + | A l' |
< | < | ||
- | [root@centos8 | + | root@debian11:~# cat / |
#!/bin/sh | #!/bin/sh | ||
# atrun uid=0 gid=0 | # atrun uid=0 gid=0 | ||
# mail trainee 0 | # mail trainee 0 | ||
umask 22 | umask 22 | ||
- | LS_COLORS=rs=0:di=38\; |