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:
1
apt install smartmontools ssmtp -y
Permissions: Ensure passwordless
sudo
access forsmartctl
by adding the following line to/etc/sudoers
:1
$USER ALL=(ALL) NOPASSWD: /usr/sbin/smartctl
$USER
is the system user running the script.Email Configuration: Configure
ssmtp
in/etc/ssmtp/ssmtp.conf
with 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.com
with the recipient’s email. - Replace
server@example.com
with the sender email (must matchssmtp
configuration).
- Replace
Customize Disks: Modify the
disks
array to include relevant disk devices (e.g.,/dev/nvme0n1
for NVMe drives).Test Execution:
Save the script as
smart-report.sh
.Grant execute permissions:
1
chmod +x smart-report.sh
Run 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).