Want to to use my online generator?
The crontab will automatically perform recurring tasks.
- /var/spool/cron/tabs/user (SuSE GNU/Linux)
- /var/spool/cron/crontabs/user (Debian GNU/Linux and Ubuntu)
- /var/cron/tabs/user (FreeBSD et OpenBSD)
Crontab is the program name to edit the configuration table of cron. The crontab command edits a file on the user who executes it, and checks it syntax. This file is often in the /var tree:
The cron file for the root user on an Ubuntu machine will be in:
Some systems also have a centralized crontab in /etc/crontab.
To edit the cron table, just run the following command:
crontab -ewill launch the default editor (usually vi) with the current table (or an empty file if the first launch from crontab).
Each line of the file corresponds to a task to perform, informed as follows:
mm hh dd MMM DDD task > logWhere:
- mm represents minutes (0-59)
- hh represents the hour (0-23)
- dd represents the day number of month (1-31)
- MMM represents the month number (1 to 12) or the abbreviated month name (jan, feb, mar, apr, ...)
- DDD is the abbreviated name of day or the number corresponding to the day of the week (0 is Sunday, 1 represents Monday, ...)
- task represents the command or shell script to run
- log is the name of a file in which to store the log of operations. If the clause >log is not specified, cron will automatically send a confirmation email. To avoid this, simply specify ">/dev/null"
- * : At each time unit
- 2-5: time units 2,3,4,5
- */3 : all three time units (0,3,6 ,...)
- 5,8 : 5 and 8 time units
Suppose we want to establish an automated diary (in the file / logs / log_df.log example) of free disk space (df) at specific time intervals::
- Every day at 23:30:
30 23 * * * df >> /logs/log_df.log
- Every hour past 5 minutes:
5 * * * * df >> /logs/log_df.log
30 23 1 * * df >> /logs/log_df.log
28 22 * * 1 df >> /logs/log_df.log
12 10 2-5 * * df >> /logs/log_df.log
59 23 */2 * * df >> /logs/log_df.log
*/5 * * * * df >> /logs/log_df.logIt is also possible to automatically execute more complex commands using a shell script. Simply declare it as a job in the cron table.
Video tutorial of Crontab usage