ServerAvatar Logo

How to Schedule Tasks with cron in Linux

  • Author: Dishang Soni
  • Published: 19 September 2025
  • Last Updated: 19 September 2025
How to Schedule Tasks with cron in Linux

Table Of Contents

Schedule Tasks with cron in Linux to automate routine jobs like sending reminders, cleaning files, or running backups without lifting a finger. Cron acts like your personal assistant, working 24/7 to silently schedule and execute tasks at the exact time you want.

Managing tasks efficiently on Linux system often means automating repetitive jobs. Instead of manually running scripts or commands, you can use cron, one of the most powerful task schedulers built into Linux. Whether you want to automate system maintenance, schedule backups, run scripts at specific times, cron makes the process seamless.

In this guide, we’ll walk through everything you need to know about scheduling tasks with cron in Linux, from the basics of cron syntax to advanced scheduling tips.

What is cron in Linux?

cron is time-based job scheduler. It allows users to schedule commands or scripts to run automatically at specific times, dates, intervals. The name comes from the Greek word chronos, that means “time.”

Cron jobs are incredibly useful for automating routine tasks such as:

  • Running backups
  • Clearing cache
  • Sending automated reports
  • Monitoring server health
  • Updating system packages
  • and many more

Understanding How cron Works

At its core, cron relies on background process (cron daemon) that checks the crontab (cron table) for scheduled tasks. When system clock matches schedule defined in crontab, the corresponding command is executed.

Key components include:

  • cron daemon (crond): Runs continuously in background.
  • crontab file: Stores list of cron jobs for each user.
  • cron syntax: Defines time and frequency of tasks.

Cron Job Syntax Explained

The syntax of cron job may seem intimidating at first, but once you break it down, it’s straightforward:

* * * * * command-to-execute
- - - - -
| | | | |
| | | | +----- Day of the week (0-6, Sunday=0)
| | | +------- Month (1-12)
| | +--------- Day of month (1-31)
| +----------- Hour (0-23)
+------------- Minute (0-59)
Schedule Tasks- ServerAvatar

Example:

30 2 * * * /home/user/backup.sh

Each * represents a field:

  1. Minute (0–59)
  2. Hour (0–23)
  3. Day of the month (1–31)
  4. Month (1–12)
  5. Day of the week (0–6, where 0 = Sunday)

Special Strings in cron

Instead of using numbers, cron also supports special strings for common schedules:

  • @reboot → Run once at system startup.
  • @yearly or @annually → Run once a year.
  • @monthly → Run once a month.
  • @weekly → Run once a week.
  • @daily or @midnight → Run once a day.
  • @hourly → Run once an hour.

Example:

@daily /usr/bin/updatedb

This updates the file index once a day.

Creating and Editing Cron Jobs

To create or edit a cron job, use:

crontab -e

This opens the crontab file in system’s default editor. You can then add new jobs or modify existing ones.

Viewing Existing cron Jobs

To see what jobs are already scheduled, use:

crontab -l

This will list all jobs set for current user.

Removing and Disabling cron Jobs

  • To remove all jobs:
crontab -r
  • To remove specific jobs, edit the crontab (crontab -e) and delete line.
  • To temporarily disable job, add at the beginning of the line.

Example:

0 5 * * 1 /usr/bin/apt update && /usr/bin/apt upgrade -y

This updates and upgrades system every Monday at 5 AM.

Managing User and System Crontabs

Linux supports two main types of crontabs:

1. User crontabs:

Each user can set up their own scheduled tasks.

Stored in /var/spool/cron/crontabs/username.

2. System-wide crontabs:

  • Used by system administrator.
  • Stored in /etc/crontab.
  • Also, scripts can be placed in /etc/cron.daily//etc/cron.hourly/, etc.

Real-Life Examples of cron Jobs

  • Clear temporary files every day:
0 1 * * * rm -rf /tmp/*
  • Check system updates weekly:
0 3 * * 0 apt update && apt upgrade -y
  • Send an email report daily:
0 9 * * * /home/user/email_report.sh
  • Run script every 15 minutes:
*/15 * * * * /home/user/script.sh
  • Clear cache every night:
0 0 * * * rm -rf /tmp/*
  • Restart Apache every Sunday at midnight:
0 0 * * 0 systemctl restart apache2

Best Practices for Using Cron

To ensure smooth scheduling, keep these best practices in mind:

  1. Use absolute paths → Always provide full path to commands and scripts.
  2. Test commands before scheduling → Run your script manually to confirm it works.
  3. Log outputs  Store logs for troubleshooting.
  4. Use least privileges → Don’t schedule root jobs unless necessary.
  5. Keep it simple → Avoid overly complex schedules in one line.

Managing cron Jobs Easily with ServerAvatar

ServerAvatar is platform to simplify hosting and management of servers and applications. It simplifies process of deploying and managing PHP and Node.js based web applications on servers. If you’re using ServerAvatar to manage your servers and applications, deploying and managing your WordPress is incredibly simple, and it is very easy to install and activate AI-powered security tools for your WordPress site.

ServerAvatar Cron Jobs Generator:-

it is a free online utility that helps you build and understand cron expressions easily. 
It provides: 

Cron Job Generator - ServerAvatar
  • User-friendly inputs for each cron field: minute, hour, day of month, month, day of week. 
  • Predefined common schedules (e.g. every 15 minutes, daily at midnight, weekdays at 9 AM) for instant use. 
  • Explanation of the cron syntax, including allowed values, special characters, and typical examples. 
  • A step-by-step guide to using the generated cron expression in ServerAvatar (in its Cronjobs section) along with the command you want to run. 

Visit the link:- https://serveravatar.com/cron-generator/

How To Generate Cronjob With ServerAvatar

ServerAvatar Dashboard

While cron is powerful, managing it directly through the terminal can feel overwhelming, especially for beginners. That’s where ServerAvatar makes things easier.

With ServerAvatar’s user-friendly platform, you can create, update, enable, disable, or delete cron jobs in just a few clicks, no complex commands required. This means you can focus more on your applications and automation, while ServerAvatar takes care of the heavy lifting in the background.

Whether you’re a developer, agency, or business owner, ServerAvatar simplifies server management and makes cron scheduling accessible to everyone.

Cronjob - ServerAvatar

To create a cron job easily with ServerAvatar, click on the create button and fill up the required details like Name, User, Command to execute, and Schedule and click on Create Cronjob button.

Create Cronjob - ServerAvatar

Troubleshooting Cron Jobs

Sometimes cron jobs don’t work as expected. Here’s how to troubleshoot:

  1. Check system logs:
    • grep CRON /var/log/syslog (Debian/Ubuntu)
    • grep CRON /var/log/cron (CentOS/RHEL)
  2. Verify permissions: Ensure the script is executable.
  3. Confirm environment variables: Cron uses minimal environment.
  4. Check mail output: Cron sends job output to the user’s email.

Advanced Cron Scheduling Techniques

Cron supports advanced scheduling:

Multiple values:

0 9,17 * * * /home/user/script.sh
  • Runs at 9 AM and 5 PM.

Ranges:

0 9-17 * * * /home/user/script.sh
  • Runs every hour between 9 AM and 5 PM.

Step values:

*/10 * * * * /home/user/script.sh
  • Runs every 10 minutes.

CronJob Terms

Cron
Cron is background service on servers that automates task scheduling based on time. It is commonly used to trigger scripts or applications automatically at fixed intervals, handling routine operations like sending emails, updating reports, or performing backups.

You can configure cron tasks to execute once, daily, weekly, monthly, or at very specific times. Most implementations give flexibility to run jobs on certain days, dates, or hours. When scheduled moment arrives, the cron service initiates the task.

Cron Jobs
These are actual tasks created and managed by cron service with defined timing and commands.

Cron jobs may be set to run at:

  • An exact date and time: executes at that precise moment.
  • A specific hour of the day: executes within the designated hour (0–23).

Each cron job consists of three elements: timing pattern, command to execute, and user who triggers it. The cron daemon, running on Unix-like systems, ensures these commands are carried out at the right intervals.

Crontab
This is configuration file that holds all cron job definitions. The crontab file lists every job along with its schedule and is typically stored in /etc/cron.d. Users can add, remove, or modify tasks through the crontab interface.

Crontab Editor
An easy-to-use tool designed for editing crontab files without needing programming knowledge.

Conclusion

cron is one of the most reliable and powerful tools in Linux for automating repetitive tasks. From running backups to cleaning up files and monitoring system health, it takes care of jobs that you would otherwise need to remember and run manually. Once you get comfortable with cron syntax, you’ll realize how much time and effort it saves.

And if working with command line feels overwhelming, platforms like ServerAvatar make cron job management even more effortless with simple, user-friendly interface. Whether you’re beginner or seasoned Linux user, mastering cron will give you more control over your server and free you up to focus on the tasks that matter most.

With right setup, you can let cron handle routine work while you focus on what truly matters, building, managing, and growing your projects.

FAQs

1. What is the main purpose of cron in Linux?

cron is used to schedule and automate repetitive tasks, such as running scripts, backups, or system maintenance, at specific times or intervals.

2. How do I view all the cron jobs set on my system?

You can use command crontab -l to view all cron jobs for the current user. For system-wide jobs, check /etc/crontab.

3. Can cron run tasks if my system is turned off?

No, cron requires the system to be running. 

4. Why is my cron job not running as expected?

Common reasons include incorrect syntax, missing absolute paths, permission issues, or environmental variables not being set. Checking system logs often helps identify the issue.

5. How is ServerAvatar useful for managing cron jobs?

With ServerAvatar’s userfriendly platform, you can create, edit, enable, disable, or delete cron jobs without using command line. This makes automation accessible even for users who aren’t comfortable with Linux commands.

Deploy your first application in 10 minutes, Risk Free!

Learn how ServerAvatar simplifies server management with intuitive dashboards and automated processes.
  • No CC Info Required
  • Free 4-Days Trial
  • Deploy in Next 10 Minutes!