crontab
Overview
The crontab command is used to maintain crontab files for individual users. It allows users to schedule tasks (commands or scripts) to run automatically at specified times.
Syntax
crontab [-u user] [-l | -r | -e] [-i]Common Options
| Option | Description |
|---|---|
-l |
List current crontab |
-e |
Edit current crontab |
-r |
Remove current crontab |
-i |
Prompt before deleting |
-u user |
Specify user’s crontab |
Key Use Cases
- Schedule periodic tasks
- Automate system maintenance
- Regular backups
- Log rotation
- Data synchronization
Examples with Explanations
Example 1: Edit Crontab
crontab -eOpens the crontab file in default editor
Example 2: List Current Jobs
crontab -lShows all scheduled cron jobs
Example 3: Common Cron Entry
0 2 * * * /usr/bin/backup.shRuns backup.sh at 2 AM daily
Understanding Output
Crontab Format:
* * * * * command
│ │ │ │ │
│ │ │ │ └─ Day of week (0-7)
│ │ │ └─── Month (1-12)
│ │ └───── Day of month (1-31)
│ └─────── Hour (0-23)
└───────── Minute (0-59)
Common Usage Patterns
Run every hour:
0 * * * * commandRun every day at midnight:
0 0 * * * commandRun every 15 minutes:
*/15 * * * * command
Performance Analysis
- Avoid resource-intensive jobs during peak hours
- Use appropriate logging
- Monitor job duration
- Consider job dependencies
- Check system load impact