How to set up cron jobs on your VPS

Cron jobs are scheduled tasks that run automatically at fixed times on your Linux VPS. They are essential for automating backups, restarts, cleanup scripts and other recurring work.

How does cron work?

The cron daemon runs continuously in the background and executes tasks based on a schedule you define in a crontab file. Every user on the system can have their own crontab.

Opening and editing the crontab

Open your crontab with:

crontab -e

The first time, the system asks which editor you want to use. Choose nano if you are not comfortable with vim.

Cron syntax

Each line in the crontab has five time fields followed by the command:

minute hour day month weekday command

Some examples:

  • 0 3 * * * /root/backup.sh runs the backup script every night at 03:00.
  • */15 * * * * /root/check-server.sh runs every 15 minutes.
  • 0 6 * * 1 apt update && apt upgrade -y runs every Monday at 06:00.
  • 0 */4 * * * systemctl restart minecraft restarts the server every 4 hours.

An asterisk (*) means "every". A slash (/) indicates an interval.

Practical examples

Daily backup:

0 4 * * * tar -czf /root/backups/server-$(date +\%Y\%m\%d).tar.gz /home/minecraft/server/world

Restart the server at 06:00:

0 6 * * * systemctl restart minecraft

Clean up old log files:

0 2 * * 0 find /var/log -name "*.gz" -mtime +30 -delete

Output and errors

By default, cron sends the output of tasks to the system user's email. On a VPS without a mail server, it is more practical to redirect output to a log file:

0 3 * * * /root/backup.sh >> /var/log/backup.log 2>&1

The 2>&1 part sends both regular output and error messages to the same file.

Common mistakes

  • Incorrect paths: cron runs with a limited environment. Always use absolute paths for both commands and files.
  • Forgetting permissions: make sure your script is executable with chmod +x script.sh.
  • Environment variables: variables from your shell profile are not available in cron. Define them at the top of your crontab or inside the script itself.

A powerful VPS for all your automated tasks? Check out our VPS hosting plans.

How do I check if my cron job is working?

Check the syslog with grep CRON /var/log/syslog. This shows when cron started a task. Also check your own log files if you redirect output.

Can I set up cron jobs as a non-root user?

Yes. Every user can run crontab -e and schedule their own tasks. Those tasks run under that user's permissions. For system-wide tasks, use /etc/crontab or files in /etc/cron.d/.

What if my server is in a different time zone?

Cron uses the system time zone. Check it with timedatectl. To change the time zone, use timedatectl set-timezone Europe/Amsterdam.


Still stuck? Open a support ticket, our team is happy to help.

Back to the knowledge base