ACLClouds
ACLClouds

Crontab generator

Build a crontab line field by field, read it in plain English and see its next 5 run times. @daily macros, */5 steps. Free, runs in your browser.

Set the minute, hour, day and month, or paste a cron expression: the generator validates it, explains it in plain English, computes the next runs and writes the line to paste into crontab -e.

Crontab syntax

A crontab line has five time fields separated by spaces, followed by the command: minute, hour, day of month, month, day of week. 30 2 * * 1 /usr/local/bin/backup.sh runs the backup every Monday at 02:30.

Values Field, in order Example
0-59 Minute */15: every 15 minutes
0-23 Hour 9-17: from 9 am to 5 pm
1-31 Day of month 1,15: the 1st and the 15th
1-12 Month (or JAN to DEC) */3: every third month
0-7 Day of week (0 and 7 = Sunday, or SUN to SAT) 1-5: Monday to Friday

Operators and macros

Each field accepts * (every value), a comma-separated list (1,15,30), a range (1-5) and a step after * or after a range (*/10, 0-30/10). A step after a single number, such as 5/10, is rejected: write 5-59/10.

A macro replaces all five fields:

Macro Equivalent When
@reboot — When the cron service starts, so at server boot
@hourly 0 * * * * Every hour, at minute 0
@daily 0 0 * * * Every day at midnight (also @midnight)
@weekly 0 0 * * 0 Sunday at midnight
@monthly 0 0 1 * * The 1st of the month at midnight
@yearly 0 0 1 1 * January 1st at midnight (also @annually)

The cron manual on Debian and Ubuntu does not allow names (MON, JAN) inside ranges or lists: for 1-5, stick to numbers.

Day of month and day of week: the OR rule

When both fields are restricted, cron runs the job when either one matches. 0 0 1 * 1 runs on the 1st of every month and also every Monday, not only on Mondays that fall on the 1st.

If one of the two fields starts with *, only the other one counts. Cron only looks at the first character: */2 in the day of month counts as * and the rule becomes an AND again. To target the first Monday of the month, limit the days to 1-7 and test the weekday in the command: 0 9 1-7 * * [ "$(date +\%u)" = 1 ] && /usr/local/bin/report.sh.

Installing the line and avoiding the usual traps

  • crontab -e opens your crontab in the editor and crontab -l prints it. crontab -r deletes it without asking: keep a copy with crontab -l > crontab.bak.
  • Cron starts with a minimal environment: PATH is /usr/bin:/bin and your .bashrc aliases and variables do not exist. Use absolute paths (/usr/bin/php, /usr/local/bin/node) or add a PATH=… line at the top of the crontab.
  • The % character is special: cron turns it into a newline and sends the rest to standard input. Write \% in the command, for example date +\%F.
  • Redirect the output to keep a trace: >> /var/log/backup.log 2>&1. Otherwise cron emails it to the crontab owner, which needs a mail server; MAILTO="" turns those emails off.
  • Read cron activity with journalctl -u cron (Debian, Ubuntu) or journalctl -u crond (Rocky, AlmaLinux, Fedora), or in /var/log/syslog when rsyslog is installed.
  • /etc/crontab and the files in /etc/cron.d have one more field before the command: the user that runs the job, for example root.
  • The last line must end with a newline, otherwise cron may reject it.

Time zones and systemd timers

Cron follows the server time zone, often UTC on a fresh VPS. Check it with timedatectl, change it with sudo timedatectl set-timezone Europe/London, then restart cron. The CRON_TZ variable exists in cronie (Rocky, AlmaLinux, Fedora), but the cron shipped with Debian and Ubuntu has no per-user time zone.

On a system with systemd, a timer is an alternative: OnCalendar=*-*-* 03:00:00 in a .timer file, Persistent=true to catch up on a run missed while the machine was off, output in journalctl and upcoming runs listed by systemctl list-timers.

Frequently asked questions

How do I run a script every 5 minutes with cron?

Add */5 * * * * /path/to/script.sh with crontab -e. The script must be executable (chmod +x) or called through its interpreter, for example /bin/bash /path/to/script.sh.

Why is my cron job not running?

Common causes: a program without an absolute path (minimal PATH), an unescaped %, a script that is not executable, or a different time zone than expected. Append >> /tmp/cron.log 2>&1 to the command to read the error, and check journalctl -u cron.

What does * * * * * mean?

Every minute of every day. Cron reads the crontab once a minute, so that is the finest schedule it offers.

Is Sunday 0 or 7?

Both. The day-of-week field accepts 0 to 7, where 0 and 7 are Sunday, as well as the abbreviations SUN to SAT.

In which time zone does my crontab run?

In the server time zone. On a fresh VPS that is often UTC, so 0 3 * * * runs at 03:00 UTC whatever your local time is. timedatectl shows the zone in use.

Does the generator send my data anywhere?

No. Parsing, the description and the run times are computed in your browser; nothing is sent to ACLClouds.