How to configure smartd and be notified of hard disk problems via email - LinuxConfig.org

We will talk about the smartd daemon: we will see how to schedule tests and how to configure it to so to be notified via email when an error is found on a storage device. In the course of the article I will assume the smartmontools package to be already installed. Please refer to the aforementioned article for installation instructions. This is a companion discussion topic for the original entry at https://linuxconfig.org/how-to-configure-smartd-and-be-notified-of-hard-disk-problems-via-email

I followed the guide and msmtp is working; however, email alerts from smartd aren’t working. Any advice?

Hi Discipulus,

Welcome to our forums.

Do you see any relevant error messages in the logfiles?

Have the same problem… I can use msmtp from the command line fine. So I know it is setup right with the email account I configured for its use. The /var/log/msmtp.log, only shows the successful test from the command line. It does not appear that smartd even tried to invoke msmtp. The smartd log from systemctl/journalctl shows no errors, only report successful send of mail. So where else should I look for what really happened?

Hi Nodi.Rubrum,

Welcome to our forums.

So your smartd journal shows successful mail send, does that relate to the command line test, or the mail that actually never arrived?

The smartd service reported success, but it was a false report. The mail as never generated or sent. I back-tracked the issue to the fact that mail or mailx was not sending mail to an external source as directed. I installed msmtp, and then rewrote the smartd-runner script to call msmtp correctly and with the correct parameter order that msmtp needs versus the default the smartmontools (smartd) attempts on Debian 10. Not only is smartmontools staged a bit different than other distros (different paths and different dependencies) for Debian via the package creator decision, but deviates from the common use of notification via the runner script.

Ah yes, the beauty of different distros using different paths, package names, config files, service names… The list is long and quite chaotic sometimes.

Mind sharing your smartd-runner script? I can’t seem to get mine running and believe I have the same problem

Sure…

# cat /usr/share/smartmontools/smartd-runner
#!/bin/bash -e
tmp=$(tempfile)
cat >$tmp
run-parts --report --lsbsysinit --arg=$tmp --arg="$1" \
    --arg="$2" --arg="$3" -- /etc/smartmontools/run.d
rm -f $tmp

Basically mail or mailx use a different command line parameters set, than msmtp, I happen to have msmtp available so just changed the script to be compatible with msmtp.

Thank you for this nice tutorial. Unfortunately, I get the following error after starting smartd.

XXX@Server:~$ sudo service smartd status
● smartmontools.service - Self Monitoring and Reporting Technology (SMART) Daemon
     Loaded: loaded (/lib/systemd/system/smartmontools.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2023-09-08 19:11:56 CEST; 3s ago
       Docs: man:smartd(8)
             man:smartd.conf(5)
   Main PID: 3188108 (smartd)
     Status: "Next check of 6 devices will start at 19:21:56"
      Tasks: 1 (limit: 76951)
     Memory: 1.9M
     CGroup: /system.slice/smartmontools.service
             └─3188108 /usr/sbin/smartd -n --interval=600 -A /var/log/smartd/

Sep 08 19:11:56 Server smartd[3188108]: Test of <mail> to XXX@googlemail.com produced unexpected output (65 bytes) to STDOUT/STDERR:
Sep 08 19:11:56 Server smartd[3188108]: mail: cannot send message: Process exited with a non-zero status
Sep 08 19:11:56 Server smartd[3188108]: Test of <mail> to XXXX@googlemail.com: failed (32-bit/8-bit exit status: 9216/36)
Sep 08 19:11:56 Server smartd[3188108]: Device: /dev/sda [SAT], state written to /var/lib/smartmontools/smartd.WDC_WD60EZRX_00MVLB1-WD_WX11D557YXL8.ata.state
Sep 08 19:11:56 Server smartd[3188108]: Device: /dev/sdb [SAT], state written to /var/lib/smartmontools/smartd.WDC_WD60EFRX_68L0BN1-WD_WX31D8815CKJ.ata.state
Sep 08 19:11:56 Server smartd[3188108]: Device: /dev/sdc [SAT], state written to /var/lib/smartmontools/smartd.WDC_WD60EZRX_00MVLB1-WD_WX21D84PDY2J.ata.state
Sep 08 19:11:56 Server smartd[3188108]: Device: /dev/sdd [SAT], state written to /var/lib/smartmontools/smartd.WDC_WD60EFRX_68L0BN1-WD_WX31D8815UDZ.ata.state
Sep 08 19:11:56 Server smartd[3188108]: Device: /dev/nvme0, state written to /var/lib/smartmontools/smartd.INTEL_SSDPED1D280GA-PHMB73920175280CGN.nvme.state
Sep 08 19:11:56 Server smartd[3188108]: Device: /dev/nvme1, state written to /var/lib/smartmontools/smartd.INTEL_SSDPEKKW128G8-BTHH95101JMM128A.nvme.state
Sep 08 19:11:56 Server systemd[1]: Started Self Monitoring and Reporting Technology (SMART) Daemon.