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: a file in /etc/cron.d needs a user field that a personal crontab does not have

Cron
~/tips/tip-cron-cron-d-user-field

17 2 * * * root /usr/local/bin/backup.sh

Explains the extra user column that system crontab files in /etc/cron.d require.

Pasting a line from your own crontab into /etc/cron.d is a quick way to get a job that never works.

# /etc/cron.d/backup
17 2 * * * root /usr/local/bin/backup.sh

System crontab files have a sixth field, the user the command runs as, between the schedule and the command. Without it cron reads the first word of the command as a user name and the job fails. Debian ignores files in the directory whose names contain a dot, the file must be owned by root and not writable by group or others, and cron picks up changes by itself, so no restart is needed. This is the tidy place for jobs that belong to a package or a service rather than to a person.

Further reading: cron(8) manual page (Debian)

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