π Linux/Unix: Job Scheduling β cron, crontab, at, batch Commands Explained
π§² Introduction β Why Learn Job Scheduling in Linux?
Automating tasks is crucial for efficient system administration. Whether you’re running backups at night, sending email alerts, or rotating logs, Linux job scheduling tools like cron, crontab, at, and batch let you schedule commands and scripts to run periodically or once at a specific timeβno manual intervention needed.
π― In this guide, youβll learn:
- How to schedule recurring jobs using cron/crontab
- How to run one-time tasks using atandbatch
- Real command usage, examples, and common scheduling formats
π 1. cron & crontab β Repeating Jobs Scheduler
β
 What is cron?
cron is a time-based job scheduler that runs scripts or commands at fixed intervals (minutes, hours, days, etc.).
β
 What is crontab?
crontab is the table of cron jobs, storing user-defined scheduled tasks.
π οΈ Crontab Syntax Format:
*  *  *  *  *  command-to-run
β  β  β  β  β
β  β  β  β  ββ Day of week (0-7; 0 or 7 = Sunday)
β  β  β  βββββ Month (1-12)
β  β  ββββββββ Day of month (1-31)
β  βββββββββββ Hour (0-23)
ββββββββββββββ Minute (0-59)
π§ͺ Example: Run backup script daily at 2 AM
crontab -e
Add:
0 2 * * * /home/user/scripts/backup.sh
πΉ Common Crontab Commands:
| Command | Description | 
|---|---|
| crontab -e | Edit userβs crontab file | 
| crontab -l | List current cron jobs | 
| crontab -r | Remove userβs crontab | 
π§ͺ Example: Run every 5 minutes
*/5 * * * * /usr/bin/python3 /home/user/check.py
π§ Logs can be found in:
/var/log/syslog  (Debian/Ubuntu)
or
/var/log/cron    (RHEL/CentOS)
π 2. at β One-Time Job Scheduler
β
 What is at?
The at command runs a command or script once at a specific time in the future.
π οΈ Install it (if not present):
sudo apt install at   # Debian/Ubuntu
sudo yum install at   # RHEL/CentOS
Enable atd daemon:
sudo systemctl start atd
sudo systemctl enable atd
π§ͺ Example: Run script at 10:00 PM today
echo "/home/user/cleanup.sh" | at 10:00 PM
π§ͺ Example: Run at 2 AM tomorrow
at 2am tomorrow
Inside prompt:
/home/user/backup.sh
<Ctrl+D>
πΉ Other at Commands:
| Command | Description | 
|---|---|
| atq | List scheduled jobs | 
| atrm <job#> | Remove a scheduled job | 
π 3. batch β Run When System Load Is Low
β
 What is batch?
batch is like at, but it waits until system load is low to execute tasks. Ideal for non-urgent tasks.
π§ͺ Example:
echo "/home/user/reports.sh" | batch
π€ Output:
job 6 at Tue Jun 18 21:00:00 2025
π§  Uses the same backend as at.
βοΈ Tool Comparison Table
| Tool | Use Case | Frequency | Interactive? | System Load Aware | 
|---|---|---|---|---|
| cron | Recurring tasks (daily/hourly) | Repeated | No | No | 
| crontab | Define user job schedule | Repeated | No | No | 
| at | One-time future jobs | Once | Yes (prompt) | No | 
| batch | One-time jobs on low CPU | Once | Yes | β Yes | 
π Summary β Recap & Next Steps
Linux scheduling tools empower you to automate everything from backups to reports. With cron and crontab, you handle repetitive tasks. Use at or batch for ad-hoc or load-aware jobs, especially useful in scripting and DevOps pipelines.
π Key Takeaways:
- Use crontabfor scheduled recurring jobs.
- Use atfor a one-time future execution.
- Use batchto run when system is idle.
- Use atq,atrm, andcrontab -lfor job management.
β FAQs
β How do I know if cron is running?
β
 Run:
sudo systemctl status cron     # Ubuntu/Debian
sudo systemctl status crond    # RHEL/CentOS
β Where are crontab logs stored?
β
 Usually in:
/var/log/syslog
or
/var/log/cron
β Can I run GUI apps using cron?
π‘ Not recommended. GUI apps need environment variables like DISPLAY.
β How do I run a job every Sunday?
β
 Use:
0 9 * * 0 /path/to/script.sh
β Whatβs the difference between cron and at?
β
 cron runs jobs repeatedly. at runs a job only once.
Share Now :
