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:
apt install smartmontools ssmtp -yPermissions:
Ensure passwordlesssudoaccess forsmartctlby adding the following line to/etc/sudoers:$USER ALL=(ALL) NOPASSWD: /usr/sbin/smartctl$USERis the system user running the script.- Email Configuration:
Configuressmtpin/etc/ssmtp/ssmtp.confwith valid SMTP server credentials (e.g., Gmail, Outlook, or a custom SMTP server). 
Using sSMTP with Gmail
# Encryption Settings
UseTLS=YES
UseSTARTTLS=YES
# Server Configuration
mailhub=smtp.gmail.com:587
# Authentication
AuthMethod=LOGIN
[email protected]
AuthPass=xxxxxxxxxxxxxxx/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 | [email protected] | 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
cat << EOF > smart-report.sh
#!/bin/  
# Email configuration  
recipient="[email protected]"    # Replace with target email  
sender="[email protected]"      # Replace with sender email  
# Disks to monitor  
disks=("/dev/sda" "/dev/sdb" "/dev/sdc" "/dev/sdd")  
# Temporary file for email content  
tempfile=$(mktemp)  
# Email headers  
echo "To: $recipient" >> "$tempfile"  
echo "From: $sender" >> "$tempfile"  
echo "Subject: Disk S.M.A.R.T. Health Report" >> "$tempfile"  
echo "" >> "$tempfile"  
# Collect S.M.A.R.T. data  
for disk in "${disks[@]}"; do  
    echo "=== $disk S.M.A.R.T. Data ===" >> "$tempfile"  
    sudo smartctl -a "$disk" >> "$tempfile" 2>&1  
    echo -e "\n\n" >> "$tempfile"  
done  
# Send email  
ssmtp "$recipient" < "$tempfile"  
# Cleanup  
rm "$tempfile"  
EOFConfiguration Steps
Update Email Addresses:
- Replace 
[email protected]with the recipient’s email. - Replace 
[email protected]with the sender email (must matchssmtpconfiguration). 
- Replace 
 - Customize Disks:
Modify thedisksarray to include relevant disk devices (e.g.,/dev/nvme0n1for NVMe drives). Test Execution:
- Save the script as 
smart-report.sh. Grant execute permissions:
chmod +x smart-report.shRun the script:
./smart-report.sh
- Save the script as 
 
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:
# Open the crontab editor  
crontab -e  Add this line to the crontab file:
0 0 * * 1 /path/to/smart-report.sh  # Runs every Monday at 00:00  0 0: Minute (0) and hour (0 = midnight).* * 0: Day-of-week (0= Sunday,1= Monday).