Back to blog
May 23, 2026Guides

How to Set Up Cron Jobs on Linux Server

Learn cron syntax, crontab editing, common scheduling examples, and logging for automated tasks on VPS.

How to Set Up Cron Jobs on Linux Server

Cron is the standard Linux scheduler for running scripts and commands at fixed times — backups, cache clearing, certificate checks, and more. This guide shows how to use cron on your Hiddence server.

Cron syntax

Each line has five time fields followed by the command:

bash
# ┌──────── minute (0-59)
# │ ┌────── hour (0-23)
# │ │ ┌──── day of month (1-31)
# │ │ │ ┌── month (1-12)
# │ │ │ │ ┌─ day of week (0-7, 0 and 7 = Sunday)
# │ │ │ │ │
# * * * * * command

# Every day at 3:00 AM:
0 3 * * * /usr/local/bin/backup.sh

# Every 15 minutes:
*/15 * * * * /usr/local/bin/check.sh

Edit crontab

Use crontab -e for the current user. For root tasks (most system jobs), use sudo:

bash
# Edit your user crontab
crontab -e

# Edit root crontab
sudo crontab -e

# List current jobs
crontab -l
sudo crontab -l

Common examples

  • 0 2 * * * — daily backup at 2:00 AM
  • 0 */6 * * * — every 6 hours
  • 0 0 * * 0 — every Sunday at midnight
  • */5 * * * * — every 5 minutes (use carefully)
  • @reboot /path/script.sh — run once after server reboot
  • @daily /usr/bin/certbot renew --quiet — daily Certbot check

Logging and debugging

Redirect output to a log file so you know if a job failed:

bash
0 3 * * * /usr/local/bin/backup.sh >> /var/log/backup-cron.log 2>&1

# View cron execution in system log:
grep CRON /var/log/syslog   # Ubuntu
grep CRON /var/log/cron      # CentOS

Tips

  • Use absolute paths in cron commands
  • Test scripts manually before adding to crontab
  • Set MAILTO=your@email.com in crontab for error emails (if mail is configured)
  • Prefer systemd timers for complex dependencies on modern systems
  • Do not run heavy tasks every minute — it can overload the VPS