Submitted by knife on Sun, 12/01/2024 - 13:14
Mange scheduled commands using crontab
Introduction
This is a documentation about managing scheduled commands with crontab. With crontab you can install, deinstall or list the tables used to drive the cron daemon. Each user can have their own crontab.
Edit crontabs
To start editing crontabs for the current user, run:
$ crontab -eTo manage contabs as root, run:
$ sudo crontab -eTo edit crontabs as another specific user, run the following command. (Make sure you have the privileges for this user):
$ crontab -u USER -eThis will open the current crontab using an editor. If no VISUAL or EDITOR environment variables is set, you can choose one at start. To do this press a number on your keyboard and hit ENTER.
A configuration file will be shown. After you exit from your editor, the modified crontab will be installed automatically.
A line starting with # is a comment and won't be executed. At default a description and an example will be shown. To add a cronjob, begin a new line, or edit one.
The format of each job, follows this format:
MINUTE HOUR DAY-OF-MONTH MONTH DAY-OF-WEEK COMMAND-THAT-WILL-BE-EXECUTEDFor each part of the table, you have do define concrete value or type * for any, or */N (see example below). The parts values can be separated blank character.
Examples for crontabs
Run a backup of all your user accounts at 5 a.m every week with:
0 5 * * 1 tar -zcf /var/backups/home.tgz /home/Run a shell script every 2 hours (In this example cron will execute the script myscript.sh in the home directory):
* */2 * * * ~/myscript.sh
List crontabs
To list the crontabs for the current user, run:$ crontab -l
Revisions
12/01/2024 - 13:14