scrontab
Schedule automated tasks using cron
TLDR
Install a new crontab from the specified file
[e]dit the crontab of the current user
[e]dit the crontab of the specified user
[r]emove the current crontab
Print the crontab of the current user to stdout
SYNOPSIS
crontab [ -u user ] file
crontab [ -u user ] { -l | -r | -e }
crontab -i [ -u user ] { -l | -r | -e }
crontab -v [ -u user ]
PARAMETERS
-u user
Specifies the user whose crontab is to be viewed, edited, or removed. This option is typically restricted to the root user. If omitted, the operation applies to the current user.
file
Specifies the path to a file containing cron job definitions to be loaded into the current user's (or specified user's) crontab. This replaces any existing crontab.
-l
Lists the current crontab entries for the specified user or the current user to standard output.
-r
Removes the current crontab for the specified user or the current user. Use with caution.
-e
Edits the current crontab for the specified user or the current user. It opens the crontab file in the editor defined by the VISUAL or EDITOR environment variables (in that order).
-i
(interactive) Used in conjunction with -r, this option prompts the user for confirmation before removing the crontab, providing a safety net.
-v
(verbose) Displays the date and time of the last modification to the current user's crontab. This is useful for verifying recent changes.
DESCRIPTION
The command 'scrontab' is not a standard Linux command and is very likely a misspelling of 'crontab'. This analysis will therefore focus on 'crontab'.
crontab (short for 'cron table') is a fundamental utility in Unix-like operating systems used to manage scheduled tasks, also known as cron jobs, for individual users. It allows users to define commands or scripts that should be executed automatically at specified times or regular intervals. These definitions are stored in a user-specific file, also called a crontab file, which is then interpreted and executed by the cron daemon running in the background. It's an an indispensable tool for automating routine system administration tasks, data backups, log file rotations, or any periodic command execution without manual intervention. Unlike commands like at(1) which schedule one-time jobs, crontab is designed for recurring tasks, making it a cornerstone for system automation.
CAVEATS
As noted in the description, 'scrontab' is not a standard command and is almost certainly a typo for 'crontab'.
When using crontab, keep the following in mind:
Syntax Sensitivity: The crontab file format is extremely strict. Even minor syntax errors can prevent jobs from running without explicit error messages, making debugging challenging.
Environment Variables: Cron jobs run in a minimal environment. It's common to encounter issues with commands not found or incorrect behavior due to missing environment variables (like PATH). Always specify full paths to executables or set necessary environment variables within the crontab file.
Output Redirection: Any output (both stdout and stderr) from a cron job is, by default, mailed to the user. This can quickly fill up mailboxes if not redirected to /dev/null or a log file.
Security Considerations: Be mindful of permissions on scripts executed by cron. Misconfigured crontab entries can pose security risks.
System-wide Jobs: The crontab command manages user-specific jobs. System-wide cron jobs are typically configured in /etc/crontab or files within /etc/cron.d/, and are not managed by the crontab command itself.
CRONTAB FILE FORMAT
Each line in a crontab file (excluding comments and environment variable definitions) represents a single cron job and follows a specific six-field format:
minute hour day_of_month month_of_year day_of_week command_to_execute
- minute (0-59)
- hour (0-23)
- day_of_month (1-31)
- month_of_year (1-12 or Jan-Dec)
- day_of_week (0-7 or Sun-Sat; both 0 and 7 are Sunday)
- command_to_execute (the shell command or script path)
Wildcards (*) are commonly used to mean 'every' for a given field. For example, '* * * * *' runs a command every minute. Specific values, comma-separated lists (e.g., 1,15), ranges (e.g., 9-17), and step values (e.g., */5 for every 5 minutes) can be used within these fields.
COMMON ISSUES AND TROUBLESHOOTING
Users frequently encounter issues with cron jobs not running as expected. Common pitfalls include:
Incorrect Paths: Commands or scripts are not found because their full path is not specified, and the PATH environment variable is limited.
Environment Variables: Cron jobs run with a minimal set of environment variables. It's often necessary to explicitly set variables like PATH, HOME, or SHELL within the crontab file.
Output Handling: Unhandled output can be mailed to the user, potentially filling up the mailbox. Always redirect output (e.g., >/dev/null 2>&1) for silent jobs.
Permissions: Ensure scripts executed by cron have execute permissions.
Syntax Errors: Use crontab -e to edit, which provides basic syntax checking, but still be vigilant. Online cron editors or validators can be helpful for complex schedules.
System Logs: Check system logs (e.g., /var/log/syslog or /var/log/cron on some systems) for messages from the cron daemon regarding job execution or failures.
HISTORY
The concept of scheduling tasks with a daemon, leading to cron, dates back to early Unix systems, with implementations appearing in V7 Unix in the late 1970s. The crontab command emerged as the primary user interface for managing these scheduled tasks, providing a standardized way for users to define their own recurring jobs without needing to directly interact with the system-wide cron configuration. Over decades, it has remained a core utility across various Unix-like operating systems, with its core functionality largely unchanged, emphasizing its robust and effective design for automating routine operations.