Cron jobs fail quietly. A backup never runs, a queue doesn’t drain, a cleanup script stops rotating logs, and you find out when something else breaks. By then, the only clue is a stale timestamp and an email inbox that never got the alert.
This guide pulls apart the common ways cron goes wrong: PATH differences, missing permissions, environment vars, overlapping runs, and output that vanishes into /dev/null. It’s based on patterns you’ll see in production, then cross-checked against how cron and common schedulers behave.
You’ll learn how to confirm a job actually ran, capture logs you can trust, add simple “I’m alive” signals, and set up monitoring so failures show up before customers do. Ready to make your scheduled tasks boring again?
We’ll walk you through setting up cron jobs to run at intervals of 5, 10, 15, or 30 minutes.
What is a cron job?
A cron job is a scheduled task that runs automatically at predefined intervals on Unix-like operating systems.
It allows you to automate repetitive tasks without manual intervention, making it an essential tool for system administrators, developers, and website owners.
With cron jobs, you can execute scripts, commands, or programs at regular intervals, ensuring timely execution of critical tasks.
What is a crontab?
Simply put, a crontab is a file used to configure cron jobs. It contains a list of cron jobs, each specifying a command or script to run and the schedule at which it should execute.
The crontab format consists of five fields representing the minute, hour, day of the month, month, and day of the week, followed by the command to be executed.
Crontab allows for precise scheduling of tasks, including running them every minute, every hour, or at custom intervals like every 5, 10, 15, or 30 minutes.
For more in depth information on the ins and outs of these handy bits of code, check out our ultimate cron job guide.
Understanding the crontab format
Before creating cron expressions like every 5, 10, 15, or 30 minutes, it helps to understand how the crontab format works. A crontab line contains five time fields followed by the command you want to run.
* * * * * /path/to/your/command
| | | | |
| | | | ----- Day of the week (0 to 7)
| | | -------- Month (1 to 12)
| | ----------- Day of the month (1 to 31)
| -------------- Hour (0 to 23)
----------------- Minute (0 to 59)Each asterisk represents a time value. You can replace these with numbers, ranges, lists, or step values to create a schedule.
For example, the step value */5 means “every 5 minutes.”
This format allows precise scheduling for anything from simple recurring tasks to complex automation workflows.
How to run cron jobs
Every 5 Minutes
Running a cron job every 5 minutes is a common requirement for tasks that require frequent updates or checks. Such tasks could include checking for emails or notifications, monitoring system logs for errors or warnings, clearing temporary files, and much more.
To schedule a cron job to run every 5 minutes, enter this code:
*/5 * * * * /path/to/your/commandThis cron expression translates to “run the command every minute that is divisible by 5.” It’s a simple and effective way to make sure your task runs at 5-minute intervals without fail.
Alternative expressions for this interval
You can also write the same schedule using step ranges:
0-59/5 * * * *Or list out specific minutes manually:
0,5,10,15,20,25,30,35,40,45,50,55 * * * *All three options run your task every 5 minutes.
Every 10 Minutes
If you need a cron job to run every 10 minutes, you can use the following crontab entry:
*/10 * * * * /path/to/your/commandThis cron expression instructs the system to run the specified command every 10 minutes, providing regular updates or executing tasks at consistent intervals.
Alternative expressions for this interval
You can also write the same schedule using step ranges:
0-59/10 * * * *Or list out specific minutes manually:
0,10,20,30,40,50 * * * *All three options run your task every 10 minutes.
Every 15 Minutes
To schedule a cron job to run every 15 minutes, enter this crontab entry:
*/15 * * * * /path/to/your/commandThis cron expression ensures that your task is executed every 15 minutes, allowing for timely updates or maintenance activities on your system.
Alternative expressions for this interval
You can also write the same schedule using step ranges:
0-59/15 * * * *Or list out specific minutes manually:
0,15,30,45 * * * *All three options run your task every 15 minutes.
Every 30 Minutes
For tasks that require less frequent execution, you can schedule a cron job to run every 30 minutes using the following entry:
*/30 * * * * /path/to/your/commandThis cron expression specifies that the command should be executed every 30 minutes, providing ample time for tasks to be completed between each run.
Alternative expressions for this interval
You can also write the same schedule using step ranges:
0-59/30 * * * *Or list out specific minutes manually:
0,30 * * * *All three options run your task every 30 minutes.
More useful cron timing examples
Cron offers more flexibility than simple step values. Here are additional examples that help you schedule tasks more precisely.
Run every 5 minutes starting at minute 2
2-59/5 * * * * /path/to/your/commandThis means the task runs at 02, 07, 12, 17, 22, and so on.
Run every 10 minutes during working hours only
*/10 8-18 * * * /path/to/your/commandThis runs the task from 08:00 to 18:59 every day.
Run every 15 minutes on weekdays
*/15 * * * 1-5 /path/to/your/commandThis runs on Monday through Friday only.
Run every 30 minutes at night
*/30 0-6 * * * /path/to/your/commandThis is useful for nightly maintenance tasks.
These patterns give you more control and help avoid running tasks when they are not needed.
Practical examples of cron jobs
Here are common tasks that benefit from running on predictable intervals:
Regular cleanup
*/30 * * * * rm -rf /tmp/*Rotating logs
*/15 * * * * /usr/sbin/logrotate /etc/logrotate.confRunning backups
*/10 * * * * /usr/local/bin/backup.shRunning monitoring checks
*/5 * * * * curl -fsS https://example.com/healthcheckThese examples help you understand how cron expressions are used in real maintenance workflows.
How to prevent duplicate cron jobs from running?
Preventing duplicate cron jobs from running is essential to avoid unnecessary system load and potential conflicts.
Here are some strategies to ensure that only one instance of a cron job is running at a time:
- Use a locking mechanism: Implement a locking mechanism within your script to prevent multiple instances from running simultaneously. This can be achieved by creating a lock file or using a process management tool like flock.
- Check for running processes: Before executing the main task of your cron job, check if any previous instances are still running. You can use commands like pgrep or ps to identify existing processes and terminate them if necessary.
- Set a unique identifier: Include a unique identifier or timestamp in your cron job’s output or log files. This allows you to track when the cron job was last executed and determine if another instance is currently running.
- Adjust cron scheduling: Review your cron job schedule to be sure that the interval between executions is sufficient to complete the task. If necessary, adjust the scheduling to avoid overlapping instances.
Using these strategies, you can effectively prevent duplicate cron jobs from running and maintain the stability and efficiency of your system.
Troubleshooting common cron job issues
Even a simple cron expression may not run as expected. Here are common problems and how to fix them.
The cron job never runs
Check that the cron service is running:
sudo service cron statusThe command works manually but not in cron
Cron uses a limited environment. Add full paths:
*/5 * * * * /usr/bin/php /var/www/site/script.phpMissing environment variables
Add them directly inside your crontab:
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/binNo logs from cron
Check system logs:
grep CRON /var/log/syslogWrong user crontab
Make sure you are editing the correct user:
crontab -e
sudo crontab -eThese quick checks fix most cron job issues.
Monitoring cron jobs without logging in to the server
Cron jobs tend to fail quietly. When they do, the job often keeps running, but the result is wrong, delayed, or missing. By the time someone notices, the data is stale or a downstream system already broke.
The simplest way to monitor a cron job is to make the job prove it ran. Instead of checking logs later, have the job send a signal when it starts, finishes, or fails. If that signal does not arrive on time, something is off.
A common pattern is a heartbeat check. The cron job hits a unique URL at the end of each successful run. If the request never comes in, you know the job failed or never started. This works even if the server is up but the script crashed halfway through.
Timing matters here. Set the expected interval slightly longer than the cron schedule. For example, a job that runs every 15 minutes should alert after 20–25 minutes of silence. That buffer avoids false alarms from short delays while still catching real failures.
For longer jobs, split signals help. Send one ping at start and another at completion. If you see the start but not the finish, the job is hanging or exiting early. This is useful for backups, imports, or reports that can stall under load.
Exit codes are another signal source. Wrap your command so failures still trigger a request. A basic shell pattern looks like this:
- Run the main command
- On success, ping the “success” URL
- On error, ping the “failure” URL and exit non-zero
This keeps alerting tied to the actual outcome, not just the schedule.
Finally, monitor trends, not only outages. If a cron job usually completes in two minutes and suddenly takes ten, that is early warning. Slow jobs often fail next.
Conclusion
Cron jobs are one of the simplest and most reliable ways to automate tasks on any Unix based system. Once you understand how the crontab format works, scheduling commands at intervals such as every 5, 10, 15, or 30 minutes becomes straightforward. These expressions help you keep your system clean, automate maintenance, update services, and run monitoring tasks without manual work.
By combining step values, ranges, and time restrictions, you can fine tune your schedules to match exactly when your tasks need to run. Adding checks to prevent duplicate executions ensures your jobs stay efficient and avoid conflicts. With the right structure in place, cron becomes a dependable automation tool that supports both small scripts and critical production processes.
If you want to make sure your scheduled tasks are running smoothly, consider pairing your cron jobs with uptime and performance monitoring. A reliable monitoring tool will alert you the moment something fails, helping you fix issues before they become problems.
FAQ's
-
Yes. The step syntax is supported on all modern Linux distributions.
-
Cron uses the server’s local time unless configured otherwise.
-
No, cron’s smallest unit is one minute.
-
Run the command manually or trigger cron logs with:
sudo grep CRON /var/log/syslog -
User crontabs are stored in
/var/spool/cron/crontabs. -
Yes. For example:
0,30 8-18/2 * * * /path/to/command