Crontab : planifier des taches sous Ubuntu:
Dans cette section d'administration Linux Ubuntu Server nous allons voir de plus pres la planification des taches à l'aide de crontab schedule.
Crontab peut etre modifié directement tapant dans l'invite "crontab -e" mais ca peut s averer dangereux. Il est plus prudent de modifier un fichier ensuite charger ce fichier dans le planificateur.Ca permettra la creation des backups de la tache .Dans ce cas meme s'il y aura des soucis avec la tache planifiée, elle pourra etre relancée avec la derniere bonne configuration connue ou au moins reutilisée avec la meme façon juste avant les dernieres modifications. Mais ca necessitera toujours une personne à effectuer les modification avec une copie de la tache avant de la lancer.
Voici un exemple de fichier de planification de tache crontab pour l'utilisateur root:
/var/scripts/data/crontab.root
Voici un exemple de fichier de planification de tache crontab pour l'utilisateur root:
/var/scripts/data/crontab.root
Code:
########################################
# Name: Crontab Schedule for root user
# Author: LHammonds
############# Update Log ###############
# 2012-05-20 - LTH - Created schedule
########################################
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
# Crontab SYNTAX:
# minute(0-59) hour(0-23) day-of-month(1-31) month(1-12) day-of-week(0-6) command-to-execute
#
# Adjust the time clock
#
0 1-23 * * * /usr/sbin/ntpdate ntp.ubuntu.com > /dev/null 2>&1
#
# Backup MySQL Server
#
0 23 * * * /var/scripts/prod/mysql-backup.sh > /dev/null 2>&1
#
# Backup MySQL Database On Demand
#
0-59 * * * * /var/scripts/prod/mysql-db-backup.sh > /dev/null 2>&1
#
# Daily checks for available space
#
0 1 * * * /var/scripts/prod/check-storage.sh root 500 100 > /dev/null 2>&1
15 1 * * * /var/scripts/prod/check-storage.sh home 100 50 > /dev/null 2>&1
30 1 * * * /var/scripts/prod/check-storage.sh tmp 100 50 > /dev/null 2>&1
45 1 * * * /var/scripts/prod/check-storage.sh usr 100 50 > /dev/null 2>&1
0 2 * * * /var/scripts/prod/check-storage.sh var 100 50 > /dev/null 2>&1
15 2 * * * /var/scripts/prod/check-storage.sh srv 100 50 > /dev/null 2>&1
30 2 * * * /var/scripts/prod/check-storage.sh opt 100 50 > /dev/null 2>&1
45 2 * * * /var/scripts/prod/check-storage.sh bak 100 50 > /dev/null 2>&1
#
# Daily software upgrade check
#
0 3 * * * /var/scripts/prod/apt-upgrade.sh > /dev/null 2>&1
Code:
chown root:root /var/scripts/data/crontab.root
chmod 0600 /var/scripts/data/crontab.root
Code:
crontab -u root /var/scripts/data/crontab.root
Code:
touch /tmp/deleteme
crontab -u root /tmp/deleteme
rm /tmp/deleteme
Code:
cp /var/scripts/data/crontab.root /var/scripts/data/2012-11-28-crontab.root
vi /var/scripts/data/crontab.root (faites vos modifications)
crontab -u root /var/scripts/data/crontab.root