Difference between revisions of "Crontab"

From wikieduonline
Jump to navigation Jump to search
Line 1: Line 1:
{{Draft}}
+
== Overview ==
 +
Cron is driven by a '''crontab''' (cron table) file, a configuration file that specifies [[Unix shell|shell]] commands to run periodically on a given schedule. The crontab files are stored where the lists of jobs and other instructions to the cron [[Daemon (computer software)|daemon]] are kept. Users can have their own individual crontab files and often there is a system-wide crontab file (usually in <code>/etc</code> or a subdirectory of <code>/etc</code>) that only system administrators can edit.
  
 +
Each line of a crontab file represents a job, and looks like this:
 +
<pre>
 +
# ┌───────────── minute (0 - 59)
 +
# │ ┌───────────── hour (0 - 23)
 +
# │ │ ┌───────────── day of the month (1 - 31)
 +
# │ │ │ ┌───────────── month (1 - 12)
 +
# │ │ │ │ ┌───────────── day of the week (0 - 6) (Sunday to Saturday;
 +
# │ │ │ │ │                                  7 is also Sunday on some systems)
 +
# │ │ │ │ │
 +
# │ │ │ │ │
 +
# * * * * * command to execute
 +
</pre>
 +
The syntax of each line expects a cron expression made of five fields, followed by a shell command to execute.
  
* * * * /scripts/script.sh
+
== Logging ==
 +
Cron execution logs can be saved to specific file using [[rsyslog]] service.
 +
* In [[Ubuntu]] uncomment in <code>/etc/rsyslog.d/50-default.conf</code> the line:
 +
:<code>#cron.* /var/log/cron.log</code>
 +
: and restart rsyslog service: <code>sudo systemctl restart rsyslog</code>
 +
* In [[Debian]] uncomment in <code>/etc/rsyslog.conf </code> the line:
 +
:<code>#cron.* /var/log/cron.log</code>
  
 
== See also ==
 
== See also ==
* {{cron}}
+
* [[w:cron]]
  
  
 +
[[Category:Server administration]]
 +
[[Category:Operating systems]]
 +
[[Category:Linux]]
  
[[Category:Linux]]
+
 
 +
{{CC license}}
 +
Source: wikiversity

Revision as of 17:35, 19 January 2020

Overview

Cron is driven by a crontab (cron table) file, a configuration file that specifies shell commands to run periodically on a given schedule. The crontab files are stored where the lists of jobs and other instructions to the cron daemon are kept. Users can have their own individual crontab files and often there is a system-wide crontab file (usually in /etc or a subdirectory of /etc) that only system administrators can edit.

Each line of a crontab file represents a job, and looks like this:

# ┌───────────── minute (0 - 59)
# │ ┌───────────── hour (0 - 23)
# │ │ ┌───────────── day of the month (1 - 31)
# │ │ │ ┌───────────── month (1 - 12)
# │ │ │ │ ┌───────────── day of the week (0 - 6) (Sunday to Saturday;
# │ │ │ │ │                                   7 is also Sunday on some systems)
# │ │ │ │ │
# │ │ │ │ │
# * * * * * command to execute

The syntax of each line expects a cron expression made of five fields, followed by a shell command to execute.

Logging

Cron execution logs can be saved to specific file using rsyslog service.

  • In Ubuntu uncomment in /etc/rsyslog.d/50-default.conf the line:
#cron.* /var/log/cron.log
and restart rsyslog service: sudo systemctl restart rsyslog
  • In Debian uncomment in /etc/rsyslog.conf the line:
#cron.* /var/log/cron.log

See also


Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Terms of Use and Privacy Policy. Source: wikiversity

Advertising: