I'll help you create a Bash script for your Synology NAS to log HDD temperatures. Here's a script that should accomplish what you want:
#!/bin/bash
# Path to log file
LOG_FILE="/volume1/logs/hdd_temperatures.csv"
# Create log file with header if it doesn't exist
if [ ! -f "$LOG_FILE" ]; then
echo "datetime,temp1,temp2,temp3,temp4" > "$LOG_FILE"
fi
# Function to get HDD temperatures
get_hdd_temps() {
# Use smartctl to get temperatures for each drive
# Adjust device names (/dev/sda, /dev/sdb, etc.) to match your actual drive configurations
temp1=$(smartctl -a /dev/sda | grep "Temperature_Celsius" | awk '{print $10}')
temp2=$(smartctl -a /dev/sdb | grep "Temperature_Celsius" | awk '{print $10}')
temp3=$(smartctl -a /dev/sdc | grep "Temperature_Celsius" | awk '{print $10}')
temp4=$(smartctl -a /dev/sdd | grep "Temperature_Celsius" | awk '{print $10}')
# Get current datetime
current_datetime=$(date "+%Y-%m-%d %H:%M:%S")
# Append to log file
echo "$current_datetime,$temp1,$temp2,$temp3,$temp4" >> "$LOG_FILE"
}
# Run the temperature logging
while true; do
get_hdd_temps
sleep 60 # Wait for 1 minute
done
Here are some important notes:
-
Prerequisites:
- Install
smartmontools on your Synology NAS (you can do this via Package Center or SSH)
- Replace
/dev/sda, /dev/sdb, etc., with the actual device names of your HDDs
- Ensure the script has execute permissions (
chmod +x script_name.sh)
-
Customization:
- Change
/volume1/logs/hdd_temperatures.csv to your preferred log file location
- Adjust the number of drives and their device names as needed
-
Running the script:
- You can run this manually via SSH
- For persistent running, you might want to set up a system service or use Task Scheduler in DSM
-
Logging:
- The script creates a CSV file with datetime and temperatures
- It appends a new line every minute
- If the file doesn't exist, it creates one with a header
Recommendations:
- Rotate/manage log files to prevent them from growing too large
- Consider using
logrotate for log management
- Test the script thoroughly to ensure it works with your specific drive configuration
Would you like me to elaborate on any part of the script or explain how to set it up to run automatically?