Crontab Examples: Schedule Tasks on Linux with Cron

· 0x.cloud Team

Crontab Examples: Schedule Tasks on Linux with Cron

These crontab examples cover the schedules people need most: every few minutes, hourly, daily at a set time, weekly and at boot. Run crontab -e, paste a line such as 0 3 * * * /home/user/backup.sh, save, and cron runs it at 03:00 every day. crontab -l shows what's scheduled.

Below you'll find the syntax, a copy-paste list of cron job lines, where cron logs, and the usual reasons a job silently fails. Syntax follows man 5 crontab for the cron package that Ubuntu 24.04 LTS and Debian 12 ship by default.

Contents: Crontab syntax in one picture · Crontab examples you can copy · How to edit, list and remove cron jobs · Where cron logs · Cron job not running: common fixes · Where to run cron jobs 24/7 · Cron vs systemd · Crontab examples FAQ

Crontab syntax in one picture

┌──────── minute (0-59)
│ ┌────── hour (0-23)
│ │ ┌──── day of month (1-31)
│ │ │ ┌── month (1-12)
│ │ │ │ ┌ day of week (0-7, both 0 and 7 are Sunday)
│ │ │ │ │
* * * * * command
Operator Meaning Example
* any value * * * * * every minute
, list 0 9,18 * * * at 09:00 and 18:00
- range 0 9-17 * * 1-5 hourly, weekdays 9 to 5
/ step */15 * * * * every 15 minutes

Shortcuts replace all five fields: @reboot, @hourly, @daily, @weekly, @monthly, @yearly.

One trap: if you restrict both day of month and day of week, cron runs the job when either matches. 0 4 1 * 1 fires on the 1st of every month and on every Monday, not only on Mondays that fall on the 1st. To sanity-check an expression before saving it, paste it into crontab.guru, which spells the schedule out in plain English.

Crontab examples you can copy

Schedule Line
every minute * * * * * /path/cmd
every 5 minutes */5 * * * * /path/cmd
every 30 minutes */30 * * * * /path/cmd
every 2 hours 0 */2 * * * /path/cmd
every day at 03:00 0 3 * * * /path/cmd
twice a day 0 9,21 * * * /path/cmd
weekdays at 08:30 30 8 * * 1-5 /path/cmd
every Sunday at midnight 0 0 * * 0 /path/cmd
first day of the month 0 6 1 * * /path/cmd
once after boot @reboot /path/cmd

Real jobs from a typical VPS:

# health check every 5 minutes, log only failures
*/5 * * * * curl -fsS https://example.com > /dev/null || echo "$(date) down" >> /var/log/site-check.log

# nightly PostgreSQL dump with the date in the file name (escape % in crontab)
30 2 * * * pg_dump mydb > /home/user/backups/mydb-$(date +\%F).sql 2>> /home/user/backups/err.log

# delete dumps older than 7 days
0 4 * * * find /home/user/backups -name "*.sql" -mtime +7 -delete

# hourly Python scraper from its virtualenv
0 * * * * cd /home/user/scraper && /home/user/scraper/.venv/bin/python main.py >> scraper.log 2>&1

The % sign is special in crontab (it means newline), so date +%F must be written as date +\%F.

For a complete backup routine, see VPS backup: automatic copies and your own scripts. If old dumps and logs start filling the disk, here's how to check and free disk space on Linux.

How to edit, list and remove cron jobs

crontab -e               # edit your crontab (first run asks for an editor)
crontab -l               # list your jobs
sudo crontab -l -u bob   # list another user's jobs
crontab -r               # delete your whole crontab, no confirmation

On Ubuntu the first crontab -e asks you to pick an editor; nano is the easiest. Change it later with select-editor. In nano, save with Ctrl+O, Enter, then exit with Ctrl+X. You should see crontab: installing new crontab.

System-wide jobs go in /etc/crontab or a file in /etc/cron.d/. Those lines have a sixth field, the user to run as:

# /etc/cron.d/cleanup
0 5 * * * root apt-get clean

Where cron logs

journalctl -u cron --since today     # Ubuntu 24.04 and Debian 12
grep CRON /var/log/syslog | tail     # if rsyslog is installed

The journal only proves cron started the job. The job's own output is mailed to the local user, and on a server without mail it is lost. Always redirect: >> /path/job.log 2>&1.

Cron job not running: common fixes

Symptom Cause Fix
works in a shell, not in cron minimal PATH (/usr/bin:/bin), different working dir absolute paths, cd first
command not found in log binary lives in ~/.local/bin, nvm or a venv full path, or set PATH= at the top of the crontab
nothing happens at all script not executable chmod +x script.sh, add #!/bin/bash
command cut off unescaped % write \%
runs at the wrong hour server is in UTC check timedatectl
overlapping runs previous run still busy flock -n /tmp/job.lock /path/cmd
file in /etc/cron.d is ignored a dot in the name (job.sh) letters, digits, - and _ only: job
runs more often than expected both day of month and day of week set leave one of them as *

Variables at the top of a crontab apply to every line:

SHELL=/bin/bash
PATH=/usr/local/bin:/usr/bin:/bin
MAILTO=""

Where to run cron jobs 24/7

Cron only fires while the machine is on. Laptops sleep and desktops get shut down, so backups, reports and health checks belong on a server.

  • Backups, reports, a few scripts: an s1-1 (1 vCPU, 1 GB RAM, 15 GB NVMe) at $4.49/month is enough. Cron itself uses next to nothing; only your scripts need memory.
  • A headless-browser scraper or several bots: s1-2 (2 GB RAM) at $7.99/month.

On 0x.cloud setup is $0. With hourly billing, testing your schedule for an hour costs about $0.03, and when you delete the server the unused balance goes back to your account. See all plans on the pricing page.

Cron vs systemd

Cron is for short jobs on a clock: backups, reports, cleanup. A process that must stay up (a Telegram bot, an API, a long-running scraper) belongs in a systemd service, which restarts it after a crash. The run a Python script 24/7 guide walks through that setup.

You can hand the setup to an AI agent:

Prompt for an AI agent

Connect to my server (over SSH or through the 0x.cloud MCP). Add a cron job for my user that runs /home/user/backup.sh every day at 03:00 New York time, logging to /home/user/backup.log. Check the server timezone with timedatectl and convert, use absolute paths, then show me crontab -l.

Crontab examples FAQ

How do I run a cron job every 5 minutes? Use the step syntax in the minute field: */5 * * * * /full/path/to/script.sh. It runs at minutes 0, 5, 10 and so on, every hour of every day.

How do I list my cron jobs? Run crontab -l for your own jobs and sudo crontab -l -u username for another user. System jobs live in /etc/crontab and /etc/cron.d/.

Why does my cron job not run when the script works manually? Cron runs with a minimal PATH and none of your shell variables. Use absolute paths, redirect output to a log with >> file.log 2>&1, and check journalctl -u cron to confirm cron started it.

What timezone does cron use? Cron uses the server's system timezone. Check it with timedatectl. Many servers run in UTC, so convert your local time before writing the schedule.

Where should cron jobs run if my laptop sleeps? On an always-on server. An s1-1 on 0x.cloud ($4.49/month, about $0.030750 per hour on hourly billing) handles backups and scripts. Servers are in Warsaw, and unused balance returns to your account when you delete a server.