Linux in Action: Mastering Crontab for Task Scheduling (RHCSA & DevOps)

Published: (December 10, 2025 at 11:38 PM EST)
3 min read
Source: Dev.to

Source: Dev.to

Introduction

Task automation is a core responsibility of every Linux system administrator. Whether you’re running nightly backups, rotating logs, generating reports, or triggering DevOps workflows, the cron scheduler provides a reliable and flexible way to execute recurring jobs.

This article provides a complete, RHCSA‑aligned guide to using crontab, enriched with real‑world business use cases and practical examples you can apply immediately.

What Is Cron & Crontab?

cron is a built‑in Linux scheduler used to run commands or scripts at specific intervals. The configuration file that defines scheduled tasks is known as the crontab.

Cron is ideal for:

  • Automated system maintenance
  • Backups and cleanup tasks
  • Log rotation and reporting
  • Scheduled data transfers
  • Compliance jobs and monitoring

Cron automates repetitive tasks without human intervention, improving consistency and reliability.

Cron Syntax Explained

Every cron entry consists of five time fields followed by the command:

MIN   HOUR   DOM   MON   DOW   CMD

Important: In the editor, fields must be separated using a TAB, not a spacebar.

Field meanings

FieldDescriptionRange
MINMinute0–59
HOURHour0–23
DOMDay of month1–31
MONMonth1–12
DOWDay of week0–6 (Sun=0, Mon=1 … Sat=6)
CMDCommand to execute

Managing the Cron Service

Check if the cron service is running:

systemctl status crond

Enable the cron service at boot:

systemctl enable crond

Restart the cron service:

systemctl restart crond

User Crontabs & Scheduling Jobs

Each user can have their own crontab.

Edit crontab as a specific user

crontab -e -u username

Example: Schedule a job for user natasha to print a message on 15 June at 14:23

su natasha
crontab -e

Inside the editor add:

23  14  15  06  *   /usr/bin/echo hello

Save with ESC, then :wq.

Verify:

crontab -l -u natasha

Cron Expressions with Examples

  • Every minute

    * * * * * /usr/bin/echo "Running every minute"
  • Every 5 minutes

    */5 * * * * /usr/bin/date >> /tmp/every5min.log
  • Every 2 minutes in the first 10 minutes

    0-10/2 * * * * /usr/bin/echo "Running every 2 mins for first 10 mins"
  • Twice a day at 1:00 AM and 11:00 AM

    0 1,11 * * * /usr/bin/echo "Twice a day task"
  • Weekdays only, between 9 AM–6 PM

    0 9-18 * * 1-5 /usr/bin/echo "Weekday work hours task"

Special Cron Keywords

Some schedules do not need five fields. Cron provides helpful shortcuts:

KeywordEquivalent Schedule
@yearly / @annually0 0 1 1 *
@monthly0 0 1 * *
@daily / @midnight0 0 * * *
@hourly0 * * * *
@weekly0 0 * * 0
@rebootRun once after system boots

Example: Run a script that sends a New Year system status report on January 1st at 00:00 each year

@yearly /usr/bin/echo "Happy New Year! System status report triggered." >> /var/log/newyear.log

Running Multiple Jobs

You can schedule multiple lines in the same user’s crontab:

# Run a job every day at 14:23
23 14 * * * /usr/bin/echo hello

# Run a job every 5 minutes
*/5 * * * * /usr/bin/date >> /home/natasha/data.log

# Run a job every Sunday at midnight
0 0 * * 0 /usr/bin/echo hiyaa

Real‑World Business Use Case

Scenario: Automated Reporting & Compliance in a Retail Enterprise

A retail organization needs daily sales, inventory snapshots, and error logs automatically sent to the analytics team.

Using crontab:

  • A nightly inventory export runs at 23:59.
  • A compliance log archival runs every 6 hours.
  • A backup script runs every day at 02:00.
59 23 * * * /usr/local/bin/export_inventory.sh
0 */6 * * * /usr/local/bin/archive_logs.sh
0 2 * * * /usr/local/bin/db_backup.sh

Business impact

  • Reduces manual work for IT and operations teams
  • Ensures compliance reports are always generated on time
  • Prevents data loss through automated backups
  • Improves accuracy by eliminating human errors

Cron jobs become part of the company’s automation backbone, supporting DevOps workflows, auditing, and operational reliability.

Conclusion

Crontab is one of the most powerful automation tools in Linux. With a solid understanding of cron syntax, service management, scheduling patterns, and real‑world use cases, you can automate nearly any repetitive task on a Linux system.

Practice these examples, build your own automation routines, and incorporate cron into your RHCSA exam preparation and DevOps projects.

Back to Blog

Related posts

Read more »