Oracle Linux Basic Administration Series - Part 10 - How to Schedule Tasks with Cron and Systemd Timers in Oracle Linux
- Jason Beattie
- 19 hours ago
- 2 min read
Introduction
Automation saves time and reduces human error. In Oracle Linux, you can schedule repetitive tasks like backups, log cleanup, or updates using cron or systemd timers.
In this blog, you’ll learn how to:
Schedule jobs using cron
Use at for one-time tasks
Create and manage systemd timers (the modern replacement for cron in many cases)
Step 1: Understanding Cron
Cron is a built-in daemon that executes scheduled commands at specified times.Each user (including root) can have their own cron jobs.
The daemon runs automatically on most systems.
Check its status:
sudo systemctl status crond
If inactive:
sudo systemctl enable --now crondStep 2: Crontab Basics
To edit the current user’s cron jobs:
crontab -eTo view existing jobs:
crontab -lTo remove all jobs:
crontab -rStep 3: Cron Syntax
Use the following site.
Example – run a script every day at 2 AM
0 2 * * * /usr/local/bin/backup.sh
Example – run every Monday at 8 AM:
0 8 * * 1 /usr/local/bin/report.sh
Example – run every 15 minutes:
*/15 * * * * /usr/local/bin/monitor.sh

Step 4: System-Wide Cron Directories
In addition to user cron jobs, Oracle Linux provides system cron directories:
For example, place a script in /etc/cron.daily/ and make it executable:
sudo cp cleanup.sh /etc/cron.daily/
sudo chmod +x /etc/cron.daily/cleanup.sh
Step 5: Checking Cron Logs
Cron logs are stored in:
/var/log/cronTo view recent entries:
sudo tail -f /var/log/cron
Step 6: One-Time Jobs with at
If you want to schedule a one-time job, use the at command.
Install it (if not present):
sudo dnf install -y at
sudo systemctl enable --now atd

Schedule a job:
echo "/usr/local/bin/backup.sh" | at 02:00
List pending jobs:
atq
Remove a job:
atrm job_number
Step 7: Modern Scheduling with systemd Timers
systemd timers are more powerful and flexible than cron. They integrate with systemctl, logs, and dependency management.
Timers consist of two files:
A service file (.service) — defines what to run
A timer file (.timer) — defines when to run it
📦 Step 8: Creating a systemd Service
Create a service file:
sudo vi /etc/systemd/system/cleanup.serviceAdd:
[Unit]
Description=Daily cleanup script
[Service]
Type=oneshot
ExecStart=/usr/local/bin/cleanup.sh
Step 9: Create the Corresponding Timer
Now create the timer file:
sudo vi /etc/systemd/system/cleanup.timerAdd:
[Unit]
Description=Run cleanup script daily
[Timer]
OnCalendar=daily
Persistent=true
[Install]
WantedBy=timers.targetEnable and start the timer:
sudo systemctl enable --now cleanup.timer
Check timer status:
systemctl list-timersYou’ll see output like:

Conclusion
You’ve learned how to automate tasks in Oracle Linux using both cron and systemd timers. Automation ensures consistency and reliability key traits of a professional system admin.
In the next post, we’ll secure your server by learning how to configure and secure SSH access.



Comments