Purpose:
Collect S.M.A.R.T. (Self-Monitoring, Analysis, and Reporting Technology) data from multiple disks (/dev/sda, /dev/sdb, /dev/sdc, /dev/sdd) and automatically email the report using ssmtp.
Prerequisites
commands that require root privileges
Required Tools:
smartmontools: Retrieves S.M.A.R.T. data.ssmtp: Handles email delivery. Install both with:
1apt install smartmontools ssmtp -yPermissions: Ensure passwordless
sudoaccess forsmartctlby adding the following line to/etc/sudoers:1$USER ALL=(ALL) NOPASSWD: /usr/sbin/smartctl$USERis the system user running the script.Email Configuration: Configure
ssmtpin/etc/ssmtp/ssmtp.confwith valid SMTP server credentials (e.g., Gmail, Outlook, or a custom SMTP server).
Using sSMTP with Gmail
| |
/etc/ssmtp/ssmtp.conf Configuration
| Parameter | Value | Description | Notes |
|---|---|---|---|
AuthMethod | LOGIN | Authentication method for SMTP server | Standard method for username/password authentication |
UseTLS | YES | Enables implicit TLS encryption | Typically used with port 465 (SMTPS) |
UseSTARTTLS | YES | Enables opportunistic TLS via STARTTLS command | Typically used with port 587 |
mailhub | smtp.gmail.com:587 | SMTP server address and port | Gmail’s submission port with STARTTLS |
AuthUser | username@gmail.com | Full email address for authentication | Must match registered email in service provider |
AuthPass | email-password | App password or account password | For Gmail: Use app password if 2FA enabled |
Setup a Shell Script
| |
Configuration Steps
Update Email Addresses:
- Replace
admin@example.comwith the recipient’s email. - Replace
server@example.comwith the sender email (must matchssmtpconfiguration).
- Replace
Customize Disks: Modify the
disksarray to include relevant disk devices (e.g.,/dev/nvme0n1for NVMe drives).Test Execution:
Save the script as
smart-report.sh.Grant execute permissions:
1chmod +x smart-report.shRun the script:
1./smart-report.sh
Add Weekly S.M.A.R.T. Reports via Cron
To automate the script to run every Monday at midnight (first day of the week), add a cron job:
| |
Add this line to the crontab file:
| |
0 0: Minute (0) and hour (0 = midnight).* * 0: Day-of-week (0= Sunday,1= Monday).
