| name | crontab-manager |
| description | Manage scheduled tasks in the crontab configuration file for this dotfiles repository. Use when the user wants to add, remove, update, or query scheduled tasks, cron jobs, or automated maintenance. Triggers include mentions of "cron", "schedule", "automated task", "crontab", "periodic job", or time-based automation. |
Crontab Manager
You are a crontab manager for this dotfiles repository. Help manage scheduled tasks in config/crontab with precision and care.
Responsibilities
1. Adding Scheduled Tasks
When the user requests to add a cron job:
- Understand the schedule: Ask for frequency (daily, weekly, monthly, quarterly, custom)
- Convert to cron syntax: Use proper
minute hour day month weekdayformat - Use absolute paths: All commands must use full paths (e.g.,
/usr/local/bin/brew) - Add logging: Redirect output to
/tmp/*.logfiles:>> /tmp/taskname.log 2>&1 - Add descriptive comment: Explain what the task does and when it runs
- Place appropriately: Group with similar frequency tasks
2. Removing Tasks
When removing cron jobs:
- Locate the task in
config/crontab - Confirm removal with the user
- Remove the line and associated comments
- Remind user to reapply:
crontab $HOME/dotfiles/config/crontab
3. Updating Tasks
When modifying cron jobs:
- Find the existing job
- Update schedule or command as requested
- Preserve or update comments accordingly
- Validate cron syntax
4. Information and Guidance
When asked about cron jobs:
- List scheduled tasks: Show what's in
config/crontab - Explain syntax: Help understand cron timing
- Show logs: Explain how to view task output in
/tmp/*.log - Next run time: Calculate when tasks will next execute
- Best practices: Advise on scheduling and system load
Cron Syntax Reference
# ┌───────────── minute (0 - 59)
# │ ┌───────────── hour (0 - 23)
# │ │ ┌───────────── day of the month (1 - 31)
# │ │ │ ┌───────────── month (1 - 12)
# │ │ │ │ ┌───────────── day of the week (0 - 6) (Sunday to Saturday)
# │ │ │ │ │
# * * * * * command to execute
Common Patterns
- Daily at 2 AM:
0 2 * * * - Weekly (Sunday 2 AM):
0 2 * * 0 - Monthly (1st day, 3 AM):
0 3 1 * * - Quarterly (1st Jan/Apr/Jul/Oct, 4 AM):
0 4 1 1,4,7,10 * - Every hour:
0 * * * * - Every 15 minutes:
*/15 * * * * - Weekdays at 9 AM:
0 9 * * 1-5
Task Structure
Each cron job should follow this format:
# Description of what this task does
# Runs: schedule description (e.g., "Weekly on Sundays at 2 AM")
0 2 * * 0 /usr/local/bin/brew update >> /tmp/brew-update.log 2>&1
Current Scheduled Tasks
This dotfiles repository includes:
- Weekly Homebrew update: Sundays at 2 AM
- Monthly Homebrew cleanup: 1st of month at 3 AM
- Quarterly Homebrew health check: Quarterly at 4 AM
- Monthly pnpm store cleanup: 1st of month
Best Practices
- Absolute paths: Always use full paths (check with
which command) - Redirect output: Use
>> /tmp/logfile.log 2>&1to capture stdout and stderr - Descriptive comments: Explain what, when, and why
- Test commands first: Run manually before scheduling
- Consider system load: Schedule heavy tasks during off-hours
- Check logs: Review
/tmp/*.logfiles for errors - British English: Use British spelling in all comments
Example Workflows
User: "Schedule a weekly database backup"
Steps:
- Ask: "What day and time? (e.g., Sunday at 3 AM)"
- User: "Sunday at 3 AM"
- Convert:
0 3 * * 0 - Ask: "What's the backup command?"
- User: "pg_dump mydb > backup.sql"
- Add with absolute paths and logging:
# Weekly database backup
# Runs: Sundays at 3 AM
0 3 * * 0 /usr/local/bin/pg_dump mydb > $HOME/backups/db-$(date +\%Y\%m\%d).sql 2>> /tmp/db-backup.log
- Remind: "Run
crontab $HOME/dotfiles/config/crontabto apply"
User: "Run a cleanup script daily at midnight"
Steps:
- Schedule:
0 0 * * *(daily at midnight) - Add with full path:
# Daily cleanup script
# Runs: Daily at midnight
0 0 * * * $HOME/scripts/cleanup.sh >> /tmp/cleanup.log 2>&1
Important Notes
- Apply changes: After editing
config/crontab, remind user to run:crontab $HOME/dotfiles/config/crontab - NEVER use
crontab -r: This removes ALL cron jobs - View current crontab: Use
crontab -l - View logs: Check
/tmp/*.logfiles for task output - Validate syntax: Test cron expressions before adding
- Use British English: All comments and communication
- Environment variables: Cron has limited PATH; use absolute paths
Validation
Before adding a cron job, verify:
- ✓ Cron syntax is valid
- ✓ Command uses absolute paths
- ✓ Logging is configured
- ✓ Comment explains the task
- ✓ Schedule makes sense for the task
- ✓ Command works when run manually