brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: @reboot in a crontab runs a command at every startup

Cron
~/tips/cron-reboot

crontab -e

Runs a script once at every boot, straight from your crontab.

You do not need to write a systemd unit for every small script that has to start at boot. cron has a shortcut for it.

crontab -e

@reboot /home/me/bin/start.sh >> /tmp/start.log 2>&1

Instead of the five time fields you write @reboot. The command runs once when the cron daemon starts. The redirect keeps the output in a file, because there is no terminal to show it.

Caveat: cron starts jobs with a very small environment, so use full paths. At boot the network may not be up yet, so a script that needs it should wait or retry. This is a Linux cron feature. Not every cron implementation supports @reboot.

Further reading: crontab(5)

Going deeper: Guide: find out why a Linux service failed, with journalctl

More Cron tips echo 'systemctl restart myapp' | at 03:00 tomorrow 55 23 28-31 * * [ "$(date -d tomorrow +\%d)" = 01 ] && /usr/local/bin/month-end.sh EDITOR=nano crontab -e 30 6 * * mon /usr/local/bin/weekly-report.sh @daily /usr/local/bin/backup.sh All Cron tips (32) All topics

Link