Quick answer: Edit your schedule with crontab -e. Each line is five time fields plus a command — e.g. 0 3 * * * /usr/local/bin/backup.sh runs daily at 03:00. Always use absolute paths and check journalctl or syslog when a job doesn't fire.

Overview

Cron is the standard Linux scheduler for recurring tasks: backups, certificate renewals, queue workers, cleanups. Each user has their own crontab; system-wide jobs live in /etc/cron.d/ and /etc/cron.{daily,hourly}.

Before you start

  • SSH access as the user who should run the task.
  • The task tested manually and working from the shell first.

Step-by-step guide

  1. Open your crontab:
    crontab -e
  2. Add a schedule line — fields are minute, hour, day-of-month, month, day-of-week:
    # m  h  dom mon dow  command
    0 3 * * *        /usr/local/bin/backup.sh
    */5 * * * *      /home/user/.venv/bin/python /home/user/check.py
    0 0 * * 0        certbot renew --quiet
  3. Save and confirm: crontab -l.
  4. Capture output while testing by appending:
    0 3 * * * /usr/local/bin/backup.sh >> /var/log/backup.log 2>&1
  5. Prevent overlap of long jobs with flock:
    */10 * * * * flock -n /tmp/job.lock /usr/local/bin/job.sh

Common issues

  • Job works in shell, fails in cron: cron's PATH is minimal — use absolute paths for every binary, or set PATH= at the top of the crontab.
  • Nothing seems to run: check grep CRON /var/log/syslog (Debian family) or journalctl -u crond (RHEL family).
  • Wrong time: cron uses the server timezone — see how to set it.
  • % in commands: percent signs are special in crontab — escape as \%.

When to contact support

Cron configuration is yours on an unmanaged server; if scheduled tasks stop because the server itself misbehaves, open a ticket.

Frequently asked questions

Why does my script work in the shell but not in cron?

Cron runs with a minimal environment and PATH. Use absolute paths for every command and file in the job, or define PATH explicitly at the top of your crontab.

How can I see whether my cron job actually ran?

Check "grep CRON /var/log/syslog" on Debian-family or "journalctl -u crond" on RHEL-family, and append ">> /var/log/myjob.log 2>&1" to capture the job's own output.

How do I stop overlapping runs of a long job?

Wrap the command with flock, e.g. "flock -n /tmp/job.lock /path/to/job.sh" — the next scheduled run exits immediately if the previous one is still going.

Related articles

Need a hand? Contact Cloud2Y support →

Was this answer helpful? 0 Users Found This Useful (0 Votes)