What Does crontab Mean?
On This Page
What do you want to do?
Quick Definition
Crontab is a command used to create, edit, and manage a list of tasks that run automatically at set times on a Linux or Unix computer. You can schedule a script to run every day at midnight or every hour on the hour. It is like setting an alarm clock for your computer to do work for you without you having to be there.
Common Commands & Configuration
crontab -eOpens the current user's crontab file in the default editor (usually vi or nano). If no crontab exists, creates a new one. This is the primary method for editing scheduled tasks.
Exams test that -e edits the user's own crontab. The environment variable EDITOR determines which editor is used. Common trick: /tmp/crontab.XXXX is a temporary file.
crontab -lLists the current user's crontab entries to standard output. Useful for verifying scheduled tasks or backing up cron jobs before making changes.
Questions often ask how to view crontab contents. If no crontab exists, it outputs 'no crontab for username'. Use with -u for other users (as root).
crontab -rRemoves the current user's entire crontab without prompting. Use with extreme caution as it deletes all scheduled tasks for that user.
Exams emphasize there is no 'undo'-once removed, the crontab is gone. Often asked alongside crontab -i (interactive removal) which prompts for confirmation.
crontab -u username -eEdit the crontab of a specified user (requires root privileges). Allows admin to schedule tasks for other users, such as automated maintenance scripts running under a service account.
The -u flag is a classic exam topic-only root can use it. Non-root users who attempt it receive 'must be privileged to use -u' error.
0 5 * * 1 /usr/local/bin/weekly_report.shSchedules weekly_report.sh to run at 5:00 AM every Monday. Uses numeric day of week (1 = Monday). Commonly used for weekly system reports or maintenance.
Exams test field order: minute, hour, day of month, month, day of week. Monday is 1, Sunday is 0 or 7. A common mistake is thinking Monday is 0.
30 4 1 */2 * /usr/sbin/logrotate --force /etc/logrotate.confRuns logrotate on the first day of every even-numbered month (February, April, etc.) at 4:30 AM. Demonstrates the month field with step value (every 2 months).
Exams sometimes ask how to schedule jobs on bi-monthly intervals. The */2 in month field means every 2 months starting from January (month 1).
* * * * * /home/user/check_disk.sh > /dev/null 2>&1Runs check_disk.sh every minute and discards both standard output and standard error by redirecting to /dev/null. Prevents cron from sending email alerts about script output.
Output redirection is a frequent exam topic. Cron emails output by default. >/dev/null 2>&1 suppresses all output. Alternatively, MAILTO="" can disable email.
crontab appears directly in 18exam-style practice questions in Courseiva's question bank — one of the most-tested concepts on Cisco CCNA. Practise them →
Must Know for Exams
Crontab appears across multiple general IT certification exams, but the depth of knowledge required varies. For CompTIA A+ (Core 2), the exam may include a basic understanding of scheduling tasks in Linux using crontab as a way to demonstrate knowledge of operating system utilities. The focus is on knowing that crontab exists and that it is used for automation, but the exact syntax is typically not tested in depth.
CompTIA Linux+ is the certification where crontab is a primary objective. The exam expects you to know the five-field time syntax, environment variables like PATH and MAILTO, how to edit a user's crontab with crontab -e and -l, and how to restrict cron access using /etc/cron.allow and /etc/cron.deny. You must also understand the difference between system crontabs in /etc/crontab and user crontabs. Exam questions often present a scenario where a user reports that a script runs at the wrong time, and you must correct the crontab entry. You may also be asked to create a new crontab entry from scratch for a specific schedule.
CompTIA Security+ may mention crontab in the context of security automation and monitoring. For example, you might need to schedule a security scan every night or automate log analysis. The exam might ask which tool can be used to schedule a script file to run every night at 11 PM. Understanding that crontab is the answer helps you eliminate other wrong choices like at (which is for one-time tasks) or systemctl (for services).
In cloud certifications like AWS Certified Solutions Architect, crontab is relevant when you have an EC2 instance and want to schedule backups or maintenance scripts. While AWS offers CloudWatch Events and Lambda for serverless scheduling, the exam may present a hybrid scenario where an on-premise server uses crontab, and you need to migrate that scheduling to AWS. Knowing crontab helps you understand what the existing solution does.
For the LFCS (Linux Foundation Certified System Administrator), crontab scheduling is a core competency. You may be asked to create a crontab entry that runs a script every Sunday at 3 AM, or to modify an existing crontab to change the schedule. The exam also tests your ability to redirect output to a log file to avoid filling the mailbox with cron output.
Question types typically include multiple-choice questions about the format of a crontab line, scenario-based questions where you must write the correct cron expression, and troubleshooting questions where a cron job is not running due to missing PATH or incorrect permissions on the script file.
Simple Meaning
Imagine you have a personal assistant who does repetitive chores for you at home, like watering the plants every morning, taking out the trash every Tuesday night, and vacuuming the living room every Saturday at noon. Instead of you having to remember to do these tasks, you write them down on a piece of paper called a schedule. Your assistant then looks at this schedule and performs each task exactly when the time comes, without needing you to remind them.
In the world of computers, especially on machines running Linux or Unix, the crontab works as that schedule. The word crontab comes from two parts: cron, which is the name of the program that actually runs the tasks, and tab, which stands for table. So crontab literally means the table of tasks for cron.
When a system administrator or a developer wants a script to clean up temporary files every hour, or a server to send a daily report at 6 AM, they use the crontab command to edit a special file. This file contains lines of text, one line per task. Each line has a specific format that tells the cron program exactly when to run the command and what command to run. The format looks like five numbers or stars followed by the command. The five numbers stand for minute, hour, day of month, month, and day of week. For example, if you want something to run at 3:30 PM every Friday, you write 30 15 * * 5 /path/to/your/script.
Once you save that file, the cron program reads it and, like a diligent assistant, keeps checking the clock. When the time matches your schedule, cron activates the command or script you wrote. This automation is a fundamental part of system management because it lets machines take care of routine maintenance tasks without human intervention, making the system more reliable and freeing up people to work on more complex problems.
Full Technical Definition
Crontab, short for cron table, is a configuration file that specifies shell commands to run periodically on a given schedule. The cron daemon, cron for short, is a time-based job scheduler in Unix-like operating systems including Linux, macOS, and BSD derivatives. The daemon runs in the background and reads the crontab files to determine which commands to execute and when.
There are two main types of crontab files: system crontabs and user crontabs. System crontabs are located in /etc/crontab and in the directories /etc/cron.d/, /etc/cron.hourly/, /etc/cron.daily/, /etc/cron.weekly/, and /etc/cron.monthly/. These are used for system-wide scheduled tasks. User crontabs are stored in /var/spool/cron/crontabs/ or /var/spool/cron/ (depending on the distribution) and are associated with individual user accounts. Each user can have their own crontab file, and the commands run with that user's permissions.
The crontab file format consists of six fields per line: minute, hour, day of month, month, day of week, and the command to run. These fields are whitespace-separated. Acceptable values for minute are 0-59, hour 0-23, day of month 1-31, month 1-12 or three-letter abbreviations (jan, feb, etc.), and day of week 0-7 (where 0 and 7 both represent Sunday) or three-letter abbreviations (sun, mon, etc.). An asterisk in any field means all valid values for that field. Multiple values can be specified using commas, ranges with a hyphen, and step values with a forward slash. For example, */15 in the minute field means every 15 minutes, and 1-5 in the day-of-week field means Monday through Friday.
Environment variables can be set within a crontab file, typically at the top, before the schedule lines. Common variables include SHELL, PATH, and MAILTO. The cron daemon uses a limited environment by default, so setting PATH explicitly is a frequent practice to ensure commands are found. The MAILTO variable specifies an email address to which the output of the commands will be sent. If a command produces output or errors, cron mails that output to the owner of the crontab unless MAILTO is set or output is redirected.
Cron jobs are managed with the crontab command. The command crontab -e opens the current user's crontab file in an editor for editing. The command crontab -l displays the current crontab contents. The command crontab -r removes the user's crontab entirely. To edit another user's crontab as root, use crontab -u username -e.
In the context of general IT certifications, understanding crontab is essential for tasks like log rotation, system backups, report generation, and automated script execution. While not a core objective in every exam, it frequently appears in scenario-based questions about Linux administration, particularly in CompTIA A+, Network+, Security+, Linux+, and many cloud certification exams such as AWS Certified Solutions Architect and the LFCS.
Real-Life Example
Think about your weekly routine for taking care of a houseplant. You have a plant that needs to be watered every Wednesday at 7:00 PM. You could walk into your living room every Wednesday evening at exactly 7 PM and pour water into the pot. But sometimes you forget, or you are out of town, or you get distracted by a movie. So you decide to buy a simple water timer that attaches to the faucet and connects to a drip hose that reaches your plant. You set the timer to turn on the water every Wednesday at 7 PM for exactly 30 seconds. Now, even when you are not home, the plant gets watered. You essentially delegated the task to a device that checks the time and acts automatically.
In the IT world, the crontab works exactly like that timer. The cron daemon is the timer, and the crontab file is the schedule you program into the timer. Instead of watering a plant, you are running commands on a computer. For example, a system administrator might schedule a backup script to run every Monday at 3:00 AM because that is when the server is least busy. The script copies important files to a secondary drive. Without crontab, the administrator would have to log in each Monday at 3 AM and manually run the backup. With crontab, the computer does it automatically.
Here is a more complex analogy. Imagine you manage a small apartment building with three different recurring tasks: cleaning the hallways every Tuesday, checking the boiler on the first of every month, and collecting the trash every Friday. You create a master schedule on your fridge. Now, you are the cron daemon. Every day you wake up, check the fridge schedule, and if a task is due, you do it. You never skip a task because the schedule reminds you. That is exactly how cron works. It constantly checks the crontab files, and when the clock matches a scheduled time, it executes the associated command. This is why crontab is a foundational tool for IT automation, ensuring consistency and reliability without relying on human memory or presence.
Why This Term Matters
Crontab matters because it is one of the simplest and most powerful tools for automating routine tasks in a Linux or Unix environment. In real-world IT operations, servers must remain online and perform maintenance tasks constantly. Logs need to be rotated so they do not fill up the hard drive. Backups need to happen nightly. Security scans need to run at off-peak hours. Monitoring scripts need to check system health every few minutes. Without crontab, an administrator would have to manually schedule and execute these tasks, which is impractical for more than a handful of servers.
Crontab also enables consistency. When a task is set to run automatically, it runs the same way every time. There is no risk of administrator error from typing a wrong command or forgetting a step. This repeatability is critical for IT compliance standards like SOC 2, ISO 27001, or HIPAA, where you need to demonstrate that system maintenance occurs regularly and reliably.
crontab is available on virtually every Linux distribution and Unix-like operating system by default. This universality means that once you learn to use crontab, you can apply that skill across many environments, from a tiny Raspberry Pi to a massive cloud server cluster. In cloud computing, managed services like AWS Lambda have started replacing some cron use cases, but crontab remains relevant for EC2 instances, servers in data centers, and on-premise systems where full server control is required.
Understanding crontab also helps IT professionals debug issues. For example, if a backup is not running, you should check the crontab to see if the schedule entry is correct. If a script is running at the wrong time, you can inspect the five time fields. Troubleshooting cron jobs is a common interview question and a frequent real-world task for system administrators and IT support staff.
How It Appears in Exam Questions
In certification exams, crontab appears in several distinct question patterns. The most common is the format question. You will be given a plain English schedule and asked to select the correct crontab line. For example: Which crontab entry will run the script /home/user/backup.sh at 2:30 AM every day? The correct answer will be 30 2 * * * /home/user/backup.sh. Distractors might have the minute and hour reversed, or use commas incorrectly.
Another common pattern is the troubleshooting question. The scenario might describe a cron job that should run a script but the script never runs. You are given the crontab entry and asked to find the problem. Common traps include: the script path is relative instead of absolute, the script does not have execute permissions, the user does not have a crontab, or the cron daemon is not running. For example, a question might show 0 5 * * * backup.sh and ask why it does not work. The answer is that the full path to backup.sh is missing.
A third pattern involves environment variables. You may see a crontab file that sets PATH=/usr/bin and the command uses a command located in /usr/local/bin. The question asks why the command fails. The answer is that the PATH does not include the directory where the command lives.
In more advanced questions, you may be asked to troubleshoot output. For instance: A cron job runs but the administrator receives a huge number of emails every time it runs. The question asks how to suppress the output. The correct answer is to redirect stdout and stderr to /dev/null or to a log file.
There are also questions about crontab management commands. For example: A system administrator needs to view the crontab entries for user jdoe. Which command should be used? The answer is crontab -u jdoe -l. The distractor might be crontab -e -u jdoe which would open the file for editing, not viewing.
Finally, scenario-based questions about allowed users may appear. You might be told that user bob cannot create a crontab and asked why. The answer could be that bob is listed in /etc/cron.deny or not listed in /etc/cron.allow.
Practise crontab Questions
Test your understanding with exam-style practice questions.
Example Scenario
You are a junior system administrator at a small company. The company runs a Linux web server that hosts a customer portal. Every morning at 5:00 AM, the server needs to restart a web service to clear the cache and free up memory. Currently, the senior admin logs in manually every morning to do this. You suggest automating it with a crontab entry.
The senior admin agrees and asks you to create the crontab file for the root user. You log in to the server via SSH and become root. You type crontab -e to open the root user's crontab in the vi editor. You add a new line at the bottom of the file: 0 5 * * * /usr/bin/systemctl restart nginx. You save the file and exit.
The next morning, you check if the web service restarted automatically. You look at the logs using journalctl -u nginx and see that the service restarted at exactly 05:00:00. The senior admin is impressed. However, a few days later, the customers report that the server is slow in the mornings. You check the logs and notice that the restart is successful, but the command /usr/bin/systemctl restart nginx does not capture any error messages if something goes wrong.
To improve this, you modify the crontab entry to redirect both standard output and standard error to a log file: 0 5 * * * /usr/bin/systemctl restart nginx >> /var/log/nginx_restart.log 2>&1. Now, if the restart fails, the error will be recorded in the log file. You also add a line at the top of the crontab file to set the PATH variable: PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin. This ensures that if any script called by the restart command needs a specific binary, it will be found.
This scenario shows how crontab is used to automate a routine system maintenance task, how to adjust the environment for reliability, and how to capture output for monitoring. It also highlights the need to test the cron job after creation.
Common Mistakes
Using relative paths in the command field instead of absolute paths.
Cron runs with a very limited PATH environment variable, often just /usr/bin and /bin. If you write backup.sh without the full path, cron will not find the script unless it happens to be in one of those directories.
Always use the full absolute path to the command or script, for example /home/user/scripts/backup.sh.
Forgetting to make the script executable.
Cron executes the command directly. If the script file does not have the execute permission set, cron will fail with a permission denied error. The job will appear to run (no error email) but nothing happens.
Run chmod +x /path/to/script.sh before adding the script to crontab.
Misunderstanding the five time fields order.
The fields are minute, hour, day of month, month, day of week. A common mistake is to put hour first or to reverse minute and hour. For example, 5 0 * * * means 0:05 AM (5 minutes after midnight), not 5:00 AM.
Memorize the order: minute hour dom month dow. Use a cron syntax generator to double-check if unsure.
Not redirecting output, causing the system mailbox to fill up.
By default, cron sends an email to the user with any output (stdout and stderr) from the job. If the job produces output every time it runs, the mailbox can fill up quickly, potentially filling the disk and causing system issues.
Redirect output to a log file or to /dev/null if you do not need it. For example, add >> /var/log/myjob.log 2>&1 to the crontab line.
Editing the wrong user's crontab without using -u.
Running crontab -e as root edits root's own crontab, not another user's. If you need to edit the crontab for user 'jdoe', you must use crontab -u jdoe -e. Otherwise, tasks meant for jdoe will run as root or not at all.
Specify the target user with the -u flag: sudo crontab -u jdoe -e.
Exam Trap — Don't Get Fooled
{"trap":"A question states: Which crontab entry runs a script every Monday at midnight? The options include 0 0 * * 1 /script.sh and 0 0 * * 0 /script.sh.","why_learners_choose_it":"Learners see 'Monday' and think day-of-week 1 is correct, which it is.
But they may choose the option where day-of-week is 0 because they confuse Sunday = 0, Monday = 1. Some also confuse whether midnight is 0:00 or 24:00.","how_to_avoid_it":"Remember that midnight is 0 0 (minute 0, hour 0).
Also remember that day-of-week 0 and 7 both represent Sunday, and Monday is 1. For 'every Monday', the correct field is 1. Practice writing crontab entries for each day of the week until the mapping is automatic."
Commonly Confused With
The at command schedules a command to run once at a specific time in the future. Crontab is for recurring, permanent schedules. At jobs are deleted after execution. If you want something to run every day, use crontab. If you want to run a command at exactly 5 PM one time, use at.
To run a script once tomorrow at 3 PM, use echo /path/to/script.sh | at 3pm tomorrow. To run every day, use a crontab entry.
Systemd timers are a newer alternative to cron available on Linux systems that use systemd. They offer more features like calendar-based scheduling, monotonic timers relative to boot, and better logging integration. Crontab is simpler and more universally supported across all Unix-like systems, but systemd timers are preferred on modern Linux distributions like Ubuntu 16.04+ and CentOS 7+.
In systemd, you create a .timer and a .service file. In crontab, you add one line. For a simple task, crontab is faster. For complex dependencies, systemd timers are more powerful.
Anacron is designed for systems that do not run 24/7, like laptops. If a scheduled job is missed because the system was off, anacron will run it when the system starts again. Crontab assumes the system is always on and will skip missed jobs. Anacron is typically used for daily, weekly, and monthly tasks via /etc/anacrontab.
If you schedule a daily backup via crontab and the computer is off at that time, the backup will be lost. If you use anacron, the backup will run when the computer is turned on again.
Step-by-Step Breakdown
Check the current user's crontab
Before making changes, it is good practice to see what is already scheduled. Use the command crontab -l. This displays the existing crontab entries. If there are none, the output will say something like 'no crontab for username'. This step helps prevent duplicate tasks or accidental deletion of existing jobs.
Open the crontab file for editing
Use crontab -e to open the user's crontab file in the default text editor (usually vi or nano). The system creates a temporary copy of the crontab file for editing. This step is critical because you never edit the actual crontab file directly; the crontab command manages the file safely.
Add environment variables at the top (optional but recommended)
To avoid issues with commands not being found, set the PATH variable. Add a line like PATH=/usr/local/bin:/usr/bin:/bin. You can also set SHELL and MAILTO. These lines must come before any schedule lines. The cron daemon reads these variables and applies them to all jobs in the file.
Add the schedule line
Write a single line with the five time fields followed by the absolute path to the command. For example, 0 3 * * 1 /usr/bin/backup.sh runs backup.sh every Monday at 3:00 AM. Ensure the time fields are separated by single spaces and the command is correct. Double-check the day-of-week numbers: 0 and 7 are Sunday, 1 is Monday, etc.
Save and exit the editor
After saving the file, the crontab command checks the syntax. If there are errors, it will refuse to install the crontab and prompt you to re-edit. If the syntax is valid, the new crontab is installed. The cron daemon automatically detects the change and will use the new schedule. No restart of cron is needed.
Verify the new crontab
Run crontab -l again to confirm that your entry was saved correctly. This verifies that the edit was successful and the line is present. This step catches accidental deletions or formatting errors before you wait for the job to run.
Monitor the job's first run
Check the logs (usually /var/log/syslog or /var/log/cron) to confirm the job ran at the scheduled time. Also check the job's output or log file. This step ensures that the job executes as expected. If it does not run, you can troubleshoot by checking permissions, the script itself, or the cron service status.
Practical Mini-Lesson
When you start working with crontab in a professional environment, the first thing you must understand is that the user under which the cron job runs matters. Every job executes with the permissions of the user who owns the crontab. If the job needs to write to a directory owned by root, the job must run from root's crontab. If it needs to write to a user's home directory, it should run from that user's crontab. This is a common source of permission errors.
Next, always use absolute paths for all commands and files. The cron environment is minimal. Besides PATH being limited, the HOME variable is set to the user's home directory, but other variables like JAVA_HOME or custom scripts in non-standard locations need to be set explicitly. Many professionals create a wrapper script that exports all necessary environment variables and then executes the real task. The wrapper script is then called from crontab.
Logging is essential. Always redirect stdout and stderr to a log file. This allows you to review the output and errors after the job runs. A typical pattern is: 0 6 * * * /home/user/scripts/cleanup.sh >> /home/user/logs/cleanup.log 2>&1. If the job does not write to a log file, the only way to know it ran is to check the cron daemon's log or the system mail.
What can go wrong? The script itself might have bugs that only appear when run by cron because the terminal is not interactive. For example, a script that uses a graphical dialog will fail under cron because there is no display. Also, cron may not source the user's .bashrc or .bash_profile, so any aliases or functions defined there are not available. Scripts meant for cron should be self-contained and not rely on interactive shell settings.
Another practical point is to use cron.allow and cron.deny files. The system administrator can control which users are allowed to create crontabs. By default, any user can create a crontab. In a corporate environment, it is common to restrict cron access to only those users who need it, to prevent users from starting resource-intensive jobs on shared servers.
Finally, be aware of daylight saving time. When the clock springs forward or falls back, cron jobs that run during the changeover can run twice or not at all. For example, a job scheduled at 2:30 AM on the day of the spring forward will not run because 2:30 AM never occurs. Many production systems use UTC time for all cron jobs to avoid this issue.
Understanding crontab Scheduling Syntax
The crontab scheduling syntax is the heart of the cron system, enabling users to automatically execute scripts and commands at predefined times. Understanding this syntax is essential for system administrators and automation specialists, especially for IT certification exams like the Linux Professional Institute (LPI) or CompTIA Linux+. The syntax consists of five fields that specify minute, hour, day of month, month, and day of week, followed by the command to be executed.
Each field accepts specific values: minutes from 0 to 59, hours from 0 to 23, day of month from 1 to 31, months from 1 to 12 or abbreviated names like Jan or Dec, and day of week from 0 to 7 (Sunday is both 0 and 7) or abbreviated names like Sun or Sat. Asterisks (*) represent 'every possible value' for a field, while commas separate multiple specific values, hyphens define ranges, and forward slashes indicate step values. For example, '0 2 * * *' runs a command at 2:00 AM every day, while '*/15 * * * *' runs a command every 15 minutes.
The syntax also allows for special strings like @reboot, @yearly, @monthly, @weekly, @daily, and @hourly, which simplify common scheduling patterns. In certification exams, candidates are often tested on their ability to interpret existing crontab entries or create new ones to meet specific scheduling requirements. Mistakes commonly arise from confusing the order of fields, especially day of month and day of week, or forgetting that the day-of-week field uses 0 or 7 for Sunday.
Another common pitfall is misusing step values-for instance, '1-10/2 * * * *' will run on minutes 1, 3, 5, 7, and 9, not on minutes 2, 4, 6, 8, and 10. The command portion of a cron entry must be a single line; if you need to run multiple commands, you can separate them with semicolons, use && for conditional execution, or place them in a script file. Understanding environment variables is also critical because cron jobs run with a limited environment-user PATH is often restricted, and interactive elements like prompts or display variables are absent.
Many exam questions revolve around ensuring commands in crontab have absolute paths or explicit environment settings. For instance, if a script relies on a specific PATH or library, you might need to set PATH at the top of the crontab file. Output from cron jobs is typically emailed to the user unless redirected.
Exam questions may ask how to suppress or log cron output to a file. Mastery of crontab syntax allows administrators to automate backups, system updates, log rotations, and monitoring tasks reliably. The cryptic nature of the syntax makes it a favorite topic for multiple-choice and fill-in-the-blank questions in IT certifications, testing attention to detail and understanding of time representation in Unix-like systems.
Crontab Security and User Management for System Administrators
Managing crontab access and security is a crucial aspect of system administration, ensuring that only authorized users can schedule tasks and that those tasks do not compromise system integrity. In Unix-like systems, cron access control is managed through two configuration files: /etc/cron.allow and /etc/cron.
deny. The cron.allow file lists users who are permitted to use crontab-if this file exists, only those users can create or edit their cron jobs. The cron.deny file specifies users who are explicitly denied access.
If neither file exists, the behavior depends on the system; some systems allow all users to have crontabs by default, while others restrict it to root. Certification exams frequently test this access control mechanism, often asking which file takes precedence when both exist-cron.allow always overrides cron.
deny, meaning a user listed in cron.allow can use crontab even if also listed in cron.deny. Another common topic is the importance of restricting cron access to prevent unauthorized task execution, which could be used to run malicious scripts or escalate privileges.
System administrators must also consider the permissions of scripts invoked by cron jobs; a script owned by a regular user but setuid root might introduce vulnerabilities. The cron daemon itself runs as root, but cron jobs execute with the privileges of the user who owns the crontab. This means a user can schedule tasks that run with their own permissions, but not with root privileges unless they are root or have appropriate sudo configurations.
In exam scenarios, questions often arise about how to list another user's crontab (requires root privileges with the -u flag) or how to prevent users from using the -u flag to manipulate other users' crontabs. Security also extends to the content of the crontab files themselves-they should not be world-writable, and the cron spool directory (usually /var/spool/cron/crontabs) should be properly secured. Another key point is the use of cron environment variables like MAILTO, which can redirect cron output to a specific email address.
In a security context, administrators may disable email alerts by setting MAILTO="" to avoid filling the mail spool with repetitive messages. Cron jobs that run as root should be audited regularly to ensure no privilege escalation or unintended command execution. Some systems implement pam_cron to enforce additional authentication policies, such as requiring users to have a valid password or time-based restrictions.
Understanding these security mechanisms is vital for certification exams because they test not only the technical ability to set up cron jobs but also the administrative judgment to secure the system. Real-world scenarios often require limiting cron access for shared hosting environments, where multiple users need automation but must not interfere with each other's tasks. A well-secured crontab strategy includes regular reviews of /etc/cron.
allow and /etc/cron.deny files, logging cron job executions via syslog, and monitoring for failed jobs or unusual activity. By mastering these aspects, candidates demonstrate readiness to manage automation in production environments safely and effectively, a skill valued in system management and scripting automation domains.
Troubleshooting Clues
Symptom:
Symptom:
Symptom:
Symptom:
Memory Tip
Remember the crontab field order with the mnemonic: Minnie Mouse Hops Down Mountains Daily Wednesday. M for Minute, M for Hour? No, use: Minute John, Hour Mary, Day Dave, Month Mike, Day Week Wally. Alternatively, think of a clock: minute first, then hour, then the rest.
Learn This Topic Fully
This glossary page explains what crontab means. For a complete lesson with labs and practice, see the topic guide.
Covered in These Exams
Current Exam Context
Current exam versions that test this topic — use these objectives when studying.
Related Glossary Terms
Two-factor authentication (2FA) is a security method that requires two different types of proof before granting access to an account or system.
5G is the fifth generation of cellular network technology, designed to deliver faster speeds, lower latency, and support for many more connected devices than previous generations.
AAA (Authentication, Authorization, and Accounting) is a security framework that controls who can access a network, what they are allowed to do, and tracks what they did.
An A record is a type of DNS resource record that maps a domain name to an IPv4 address.
An AAAA record is a DNS record that maps a domain name to an IPv6 address, allowing devices to find each other over the internet using the newer IP addressing system.
Quick Knowledge Check
1.Which crontab entry runs a command every Tuesday at 3:15 PM?
2.What is the effect of creating the file /etc/cron.deny with a user's name in it?
3.A crontab entry is written as '*/5 * * * * /script.sh'. How often does /script.sh execute?
4.Which command is used to view the crontab of another user named 'jdoe' (requires root privileges)?
5.What happens if you create a crontab entry that tries to run a script located at '/usr/local/bin/backup.sh' but the user's PATH does not include '/usr/local/bin'?
6.The special string '@daily' in crontab is equivalent to which standard five-field syntax?
Frequently Asked Questions
What is the difference between cron and crontab?
Cron is the daemon that runs in the background and executes scheduled commands. Crontab is the command used to edit the file that contains the schedule. The crontab file tells the cron daemon what to run and when.
Can I schedule a job to run every 15 minutes?
Yes. Use */15 in the minute field. For example, */15 * * * * /path/to/command runs the command every 15 minutes.
How do I stop a cron job from sending email output?
Either redirect output to a file (e.g., >> /dev/null 2>&1) or set MAILTO="" at the top of the crontab file to disable email entirely.
What does the asterisk mean in crontab?
An asterisk in a field means all possible values for that field. For example, * in the month field means every month. It acts as a wildcard.
How do I edit another user's crontab?
Use the command crontab -u username -e as the root user. This opens the specified user's crontab for editing.
Why does my cron job not run when the computer is off?
Crontab assumes the system is always on. If the computer is off at the scheduled time, the job is skipped. Use anacron if you need jobs to run after the system powers on.
Can I use crontab on macOS?
Yes, macOS includes cron and crontab. However, macOS also uses launchd for scheduling. Crontab works but may not be as integrated with the system as launchd.
Summary
Crontab is a time-based job scheduler used in Unix-like operating systems to automate recurring tasks. It consists of a configuration file with one line per scheduled command, where each line defines the timing using five fields: minute, hour, day of month, month, and day of week. The cron daemon reads these files and executes the specified commands at the given times.
Understanding crontab is essential for system administrators, DevOps engineers, and anyone preparing for general IT certifications. It is a core tool for automating backups, log rotation, system monitoring, and script execution. In exams like CompTIA Linux+ and LFCS, crontab is a primary objective. Other exams like CompTIA A+, Security+, and cloud certifications treat it as useful knowledge for scenario-based questions.
The key to mastering crontab is practice. Write sample entries for common schedules, understand how to redirect output, and remember to use absolute paths. Avoid common mistakes like forgetting to set permissions on scripts or misordering time fields. With crontab, you turn a server into a reliable, self-maintaining machine that handles routine tasks without human intervention.