Revisione di Manage scheduled commands using crontab del Mer, 05/28/2025 - 14:56

Le revisioni permettono di tenere traccia delle differenze tra le diverse versioni di un contenuto.

==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 -e

To manage crontabs as root, run:

$ sudo crontab -e

To edit crontabs as another specific user, run the following command. (Make sure you have the privileges for this user):

$ crontab -u USER -e

This 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 will not be executed. By 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-EXECUTED

For each part of the table, you must either define a concrete value, or else type '''*''' (for "any"), or '''*/N''' (see example below). Use spaces to separate the parts or values from each other.

==Examples for crontabs==

To run a backup of all your user accounts at 5 a.m. every week, use:

0 5 * * 1 tar -zcf /var/backups/home.tgz /home/

To run a shell script every 2 hours (in this example, cron will execute the script ''myscript.sh'' in the ''home directory''), use:

* */2 * * * ~/myscript.sh

==List crontabs==

To list the crontabs for the current user, run:

$ crontab -l

Revisioni

05/28/2025 - 14:56
knife