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: every user can have a crontab, so check them all when a cron job is a mystery

Cron
~/tips/tip-cron-list-all-users-crontabs

sudo ls -l /var/spool/cron/crontabs

Lists the personal crontabs of every account, to find a job that runs from somewhere unexpected.

Something runs every night and nobody knows where it comes from. crontab -l only shows your own jobs, but each user on the system can have a crontab of their own, root included.

The crontabs are stored as one file per user. On Debian and Ubuntu that’s in /var/spool/cron/crontabs, with cronie on Fedora and RHEL under /var/spool/cron. As root, list which users have one:

sudo ls -l /var/spool/cron/crontabs

Then read them the proper way, with -u:

for u in $(sudo ls /var/spool/cron/crontabs); do
  echo "== $u"; sudo crontab -u "$u" -l
done

Don’t edit those files directly. The man page says they aren’t meant to be changed by hand; use sudo crontab -u name -e, so cron notices the change.

Personal crontabs are only part of the picture. System jobs live in /etc/crontab, in files under /etc/cron.d and in the /etc/cron.daily, weekly and monthly folders. And modern systems also schedule things with systemd timers, which systemctl list-timers shows. When hunting for a mystery job, I’d check all of those before blaming the application.

Further reading: crontab(1) manual page, Debian cron, crontab(1) manual page, cronie

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