UnderHost
Knowledgebase Docs

Cron jobs-schedule automated tasks

Schedule scripts and commands to run automatically. Configure cron job timing, set up backups, maintenance tasks, reports.

On this page

Cron jobs run scripts automatically at specified times. Common uses: backups, cache clearing, email reports, database maintenance, security scans.

Cron syntax

*  *  *  *  * command
│  │  │  │  │
│  │  │  │  └─ Day of week (0-6, Sunday=0)
│  │  │  └──── Month (1-12)
│  │  └─────── Day of month (1-31)
│  └────────── Hour (0-23)
└───────────── Minute (0-59)

Common examples

0 2 * * * mysqldump -u user -p db > /backup/db.sql
# Daily backup at 2 AM

0 */6 * * * wget -O - -q https://yourdomain.com/wp-cron.php?doing_wp_cron
# WordPress cron every 6 hours

0 0 1 * * /opt/cleanup.sh
# Monthly cleanup on 1st at midnight

30 9 * * 1-5 /usr/local/bin/report.sh
# Monday-Friday at 9:30 AM

Manage cron jobs

crontab -e              # Edit cron jobs
crontab -l              # List your crons
crontab -r              # Remove all crons
sudo crontab -u user -e # Edit another user's crons

Debugging crons

Check if cron ran:

grep CRON /var/log/syslog     # Linux
log stream --predicate 'process == "cron"'  # macOS

Redirect output to log file:

0 2 * * * /script.sh >> /var/log/cron.log 2>&1
Use absolute paths

Always use full paths in cron jobs. Relative paths fail because cron doesn't have your shell environment.

Related: Command line | Backups

Was this article helpful?

Need a developer-friendly server?

Use an UnderHost Cloud VPS for SSH, Git, Node.js, Python, Laravel, Docker, cron, and custom development workflows.

Related articles

Back to Developer Tools