Run a job at boot

Add an @reboot job to the current crontab. Note: the network may not be ready at boot, use systemd if you need dependencies

( crontab -l 2>/dev/null; echo '@reboot /usr/local/bin/warmup.sh' ) | crontab -

tool
cron8 commands
tags
crongitops

More cron commands

  • */5 * * * * /opt/job.sh 2>&1 | /usr/bin/logger -t job

    Send stdout and stderr to journald/syslog with a tag instead of mailing root

  • crontab - <<'EOF' MAILTO=ops@example.com PATH=/usr/local/bin:/usr/bin:/bin 0 3 * * * backup.sh EOF

    Cron has a minimal PATH. Set PATH and MAILTO at the top, or jobs fail silently

  • run-parts --test /etc/cron.daily

    List the scripts that would run, without running them. Handy for debugging cron.daily

  • systemd-run --on-calendar='*-*-* 03:00:00' --unit=backup /opt/backup.sh

    A transient OnCalendar timer with logs in journald, instead of a crontab line. Note: it is gone after reboot

  • at now + 1 hour <<< 'systemctl restart nginx'

    Schedule one delayed command. See the queue with atq, cancel with atrm

all 8 cron commands