Every FreeBSD box mails root a “daily run output” at around 3 a.m., and on most boxes nobody has read one since the install. It is a monitoring system. It ships in base, it costs nothing, and it has been quietly telling you about full disks, failed logins and setuid changes since before “observability” was a word anyone got paid for.
What actually runs
/etc/crontab has three lines that matter:
grep periodic /etc/crontab
They call periodic daily, periodic weekly and periodic monthly at fixed times. Check your own crontab for the exact schedule. periodic(8) itself is dull: it takes a directory name, runs every executable in it in lexical order, and collects the output. That is the whole program.
The scripts live in /etc/periodic/daily/, /etc/periodic/weekly/, /etc/periodic/monthly/ and /etc/periodic/security/. The numeric prefix is the ordering. You can read them, because they are shell scripts:
ls /etc/periodic/daily
Disk status, mail queue, pkg audit-style checks, rotating logs, zpool status summaries. Which ones run is decided by switches, not by deleting files.
Switches live in periodic.conf
Defaults are in /etc/defaults/periodic.conf. Never edit that file; the next upgrade overwrites it. Override in /etc/periodic.conf:
daily_status_zfs_enable="YES"
daily_scrub_zfs_enable="YES"
daily_scrub_zfs_default_threshold="35"
daily_status_smart_devices="AUTO"
The ZFS pair is the one I would turn on first. The status check puts pool health in the daily mail. The scrub knob starts a scrub when the last one is older than the threshold in days, which is a decent substitute for remembering to run one. Check periodic.conf(5) and your defaults file for the exact variable names on your release before you paste anything from a blog, including this one. The SMART line needs smartmontools installed and is worth nothing without it.
Run a section by hand to see what you just enabled:
periodic daily
That prints to your terminal instead of mailing, which is how you test a change without waiting until 3 a.m. For a single script, run it directly from /etc/periodic/daily/.
Where the output goes
daily_output, weekly_output and monthly_output decide the destination. The default is mail to root. It can be another address or an absolute file path, and a file is the right answer when the box has no working MTA and your mail has been bouncing into a spool nobody drains. If you never see the daily mail, the likely problem is not periodic. It is that root’s mail goes nowhere. Fix that first.
Exit codes decide what you see
This is the part people miss. Each script’s exit status tells periodic how to treat its output:
0: success. Shown only ifdaily_show_successis on.1: informational. Shown ifdaily_show_infois on.2: bad configuration. Shown ifdaily_show_badconfigis on.- Anything higher: a real failure, shown regardless.
The defaults hide most of the success chatter, which is why the mail stays short when things are fine and gets loud when they are not. Read the exact meanings in periodic.conf(5). If you write your own checks, this is the contract.
Add your own script
Local scripts go in a parallel tree, /usr/local/etc/periodic/daily/ and friends, so package upgrades and base upgrades leave them alone. Make it executable, number it, exit sensibly:
#!/bin/sh
# 410.cert-expiry
days=$(openssl x509 -in /usr/local/etc/ssl/site.crt -noout -checkend 1209600 >/dev/null; echo $?)
if [ "$days" -ne 0 ]; then
echo "site.crt expires within 14 days"
exit 3
fi
exit 0
openssl x509 -checkend N exits non-zero if the certificate expires within N seconds, so that script is a fourteen-day warning in six lines. Exit 3 means it always appears in the mail. The same pattern covers “replication snapshot older than a day”, which pairs nicely with zfs send and receive replication and with a pool checkpoint that someone forgot to discard.
The costs
- It is once a day. A disk that fills at noon is found at 3 a.m. the next day. This is a drift detector, not an alarm.
- The mail is plain text and long. You will learn to skim it, so make your own checks exit loud only on real problems.
- The security section diffs against yesterday’s saved state. Change a lot of setuid files on purpose during an upgrade and the next mail will say so. That is correct behavior, not a bug.
periodicdoes nothing for jails unless you enable it inside them. A jail has its own crontab and its own mail.
I spent years writing my own cron checks on FreeBSD boxes, every one of them a worse copy of something already in /etc/periodic. The first time I read the daily output start to finish I found a pool with a degraded disk that had been degraded for nine days. Nine days of mail, unread. Read the damn mail. More in the FreeBSD and OpenBSD hub and the ZFS and storage hub.
