![]() |
VOOZH | about |
Cron is a time-based job scheduling utility available in Linux and Unix-like operating systems. It runs as a background daemon process and automatically executes scheduled tasks at predefined times without user intervention. System administrators commonly use cron to automate repetitive tasks such as backups, updates, and file synchronization.
Cron operates as a background service that continuously monitors scheduled jobs and executes them when their defined time matches the system time.
Run cron in the foreground for debugging or testing purposes.
Command:
cron -fOutput:
Cron will start and continuously monitor scheduled jobs in the terminal without exiting. Logs appear directly on the console.
Ensure /etc/cron.d files follow LSB naming conventions.
Command:
cron -lExplanation:
Output:
Cron starts normally, enforcing LSB naming standards for cron configuration files. No direct terminal output unless logging is enabled.
Log the start and end of all cron jobs for monitoring.
Commnad:
cron -L 3Explanation:
Output:
Cron runs as a daemon, and logs for job start and job completion are written to the system log (e.g., /var/log/syslog or /var/log/cron.log depending on configuration).
The cron daemon can be started manually using the following syntax:
cron [-f] [-l] [-n] [-L loglevel]Note: This syntax is mainly used for debugging, testing, or container-based environments.
Runs cron in the foreground instead of as a background service. Useful for debugging or testing cron behavior.
Syntax:
cron -fExample: Check Cron Jobs in Real Time
Runs cron in the terminal, so you can see when jobs start or fail immediately.
Command:
cron -fOutput:
Cron starts and continuously monitors scheduled jobs directly in the terminal. Log messages and errors appear on the console.
Enables Linux Standard Base (LSB) compliant naming for /etc/cron.d files. Ensures cron configuration files in /etc/cron.d follow standard Linux naming rules. Helps maintain standardized cron configurations.
Syntax:
cron -lExample: Standardize Cron File Names
Useful in servers that follow Linux Standard Base (LSB) rules for configuration files.
Command:
cron -lOutput:
Cron runs normally. It will enforce correct file naming for /etc/cron.d, but no terminal output is seen unless logging is enabled.
Adds the Fully Qualified Domain Name (FQDN) to email notifications sent by cron jobs. Useful in multi-server setups.
Syntax:
cron -nExample: Identify Server in Cron Emails
If a job runs on multiple servers, this helps you know which server sent the email.
Command:
cron -nOutput:
Cron runs as a daemon. Any email sent for cron job output includes the host FQDN in the subject.
Specifies what cron should log about the jobs. You can log job start, end, failures, or process IDs.
Syntax:
cron -L <loglevel>Loglevel Values:
1: Log start of jobs
2: Log end of jobs
4: Log failed jobs (exit status β 0)
8: Log process IDs of cron jobs
Example: Log Job Start and Completion
Command:
cron -L 3Output:
Cron runs as a daemon. Job start and job completion events are logged in the system log (/var/log/syslog or /var/log/cron.log).
Crontab (cron table) is a configuration file that stores scheduled tasks. Each entry in crontab defines a command or script that should run automatically at a specific time or interval. Crontab allows users to add, modify, or remove scheduled tasks, automate repetitive operations like backups, updates, or log cleaning, run tasks in the background without manual intervention
Note: Each user can have their own crontab file, and the system also maintains a global crontab for system-wide jobs.
Each crontab entry has six fields separated by spaces. The first five fields define when the task will run, and the last field specifies what command or script to execute.
* * * * * command_to_run
| | | | |
| | | | βββ Day of Week (0β6 or SunβSat)
| | | βββββ Month (1β12 or JanβDec)
| | βββββββ Day of Month (1β31)
| βββββββββ Hour (0β23)
βββββββββββ Minute (0β59)