$ command-helper

cron and scheduled jobs

crontab syntax, editing jobs, common schedules, logging output and avoiding overlapping runs.

Requires Google sign-in

crontab

Edit your jobs
crontab -e
List your jobs
crontab -l
Jobs of another user
sudo crontab -l -u <user>
Field order
# ┌ minute (0-59)
# │ ┌ hour (0-23)
# │ │ ┌ day of month (1-31)
# │ │ │ ┌ month (1-12)
# │ │ │ │ ┌ day of week (0-7, 0 and 7 = Sunday)
# * * * * * command

Common schedules

Every 5 minutes
*/5 * * * * /opt/scripts/job.sh
Every day at 03:30
30 3 * * * /opt/scripts/backup.sh
Weekdays at 09:00
0 9 * * 1-5 /opt/scripts/report.sh
On boot
@reboot /opt/scripts/start.sh

Doing it right

Log output and errors
0 * * * * /opt/scripts/job.sh >> /var/log/job.log 2>&1
Don't start if the previous run is still goingadvanced
*/5 * * * * flock -n /tmp/job.lock /opt/scripts/job.sh
Set PATH and shell (cron has a minimal environment)advanced
SHELL=/bin/bash
PATH=/usr/local/bin:/usr/bin:/bin
MAILTO=""
Escape % in commandsadvanced
0 0 * * * tar -czf /backup/app-$(date +\%F).tar.gz /opt/app

An unescaped % ends the command in crontab.

Did the job run? (cron log)
journalctl -u cron --since today

The unit is crond on RHEL, Fedora and Amazon Linux.

Check a schedule expression online
https://crontab.guru