- Joined
- May 28, 2011
- Messages
- 10,996
This is a simple way to get SMART monitoring to report daily the status of your hard drives.
The purpose of this is to have all your SMART enabled drives report how they are doing daily. I wanted to see how many times the drives spun up and down, see if there were any flaky transmission errors because I had a bad SATA cable and it was detected through SMART.
EIDT 13 JAN 2016: Here is a link to a nice collection of scripts which expand on what this thread did. I highly recommend you check this out.
EDIT (9 OCT 2015): I didn't give this script much though when it came to implementing it and I really should have taken a better approach but you know hindsight, she's a real ... So I have made some changes below to correct this oversight on my part. The change deals with where the script resides and I have moved it from the boot device to a directory located at "/mnt/pool/scripts" and you can change this of course to your liking.
EDIT (11 November 2015): Fix typo in step 14.
This code is not persistent between upgrades of FreeNAS and must be placed back on the boot drive. You can run this from one of your hard drives however it will force them to spin up each time and you may not desire that.
This is a very simple script and implementing it will take very little time.
First the basic instructions:
NOTE: Do not type the single quotes, they are simply around the text to type. It is assumed you already have FreeNAS email all set up. Sendmail will fail if it is not set up. And "pool" is the name of your pool so change it as appropriate.
1) SSH or use the console and log in as root/SU.
2) Type 'mount -wu /'
2) Type'cd /conf/base/etc' 'cd /mnt/pool'
3) Type 'mkdir scripts'
4) Type 'cd scripts'
5) Type 'ee esmart.sh'
6) Cut and paste the script below into the editor.
Here is the simple script:
Here is the more complex script but it brings something extra (not explained like the basic code is in the below text but you should be able to understand it). In the previous script if the drive is in standby you will get a report that doesn't tell you much because the drive is not running. In this script it will periodically poll the hard drive to see if it's out of standby and then generate the report plus it cleans up the report some and more importantly you can run it on all the drives at once (same time period) where as the previous script you could only run a CRON job on one drive, wait a minute and run another CRON job. This is by far the better script of the two.
7) Edit youremail@address.net to reflect the email address you desire the report to be sent.
8) You can edit more of the script if you like but you can stop here and lets save this script, Press Escape and save it.
9) Test Run the script by typing 'sh esmart.sh /dev/ada0' NOTE: /dev/ada0 needs to be changed to your drive path. Depending on the drive adapter it could be different.
10) Wait a few seconds and check your email.
10) If it worked then lets copy it to /etc so you can run it now without having to reboot. Type:
11) Type 'mount -r /'
Now let me explain this script so you can make changes to it if you like.
The first few lines define this as a script and tell you how to call this script.
Next we assign variable switch1 for use in the commands.
Next is the code within the parentheses which define the email header and creates the file cover in the RAM based area /var to keep the hard drives from being accessed.
The key line in the script is:
This does all the real work and it will collect the data on the drive specified in switch1. The results will be added to the file cover. If the drive is not spinning then you will get an email stating the drive is in Standby and it exited. You get no data. This is fine for most people who want to minimize spinning up thier hard drives but if you really want the data everytime you run this script, remove the '-n standby' portion.
This section takes the file we created called cover and sends it via the sendmail application.
Now we will create a CRON so this script runs once a day, you can chose how often you want it to run.
12) Open FreeNAS GUI
13) On left side window click on System, Cron Jobs, Add Cron Job
14) Use the following settings: (You may set the time intervals to whatever you desire)
User: root
Command: /mnt/pool/scripts/sh esmart.sh /dev/ada0
Command: sh /mnt/pool/scripts/esmart.sh /dev/ada0
Description: ada0 SMART Results
Minute: Each selected minute: 01
Hour: Each selected hour: 01 (checking at 1 AM)
Day of month: Every N day of month: 1
Leave the rest at the default of all checked and click OK.
15) Add additional Cron Jobs for each additional drive you have.
16) Sit back and watch the reports come in.
If you would rather just have one command to check all the drives, here is a script to check 4 drives and you can modify it as you see fit.
Again, the '-n standby' will cause an issue at the point where a drive not spinning is encountered. Since I have a single pool of 4 drives, should my first drive exit due to not spinning, I can safely assume my other drives are not spinning either since I have the same HDD Standby (in FreeNAS GUI) settings for each.
-Mark
The purpose of this is to have all your SMART enabled drives report how they are doing daily. I wanted to see how many times the drives spun up and down, see if there were any flaky transmission errors because I had a bad SATA cable and it was detected through SMART.
EIDT 13 JAN 2016: Here is a link to a nice collection of scripts which expand on what this thread did. I highly recommend you check this out.
EDIT (9 OCT 2015): I didn't give this script much though when it came to implementing it and I really should have taken a better approach but you know hindsight, she's a real ... So I have made some changes below to correct this oversight on my part. The change deals with where the script resides and I have moved it from the boot device to a directory located at "/mnt/pool/scripts" and you can change this of course to your liking.
EDIT (11 November 2015): Fix typo in step 14.
This is a very simple script and implementing it will take very little time.
First the basic instructions:
NOTE: Do not type the single quotes, they are simply around the text to type. It is assumed you already have FreeNAS email all set up. Sendmail will fail if it is not set up. And "pool" is the name of your pool so change it as appropriate.
1) SSH or use the console and log in as root/SU.
2) Type
3) Type 'mkdir scripts'
4) Type 'cd scripts'
5) Type 'ee esmart.sh'
6) Cut and paste the script below into the editor.
Here is the simple script:
Code:
#!/usr/local/bin/sh # # Place this in /mnt/pool/scripts # Call: sh esmart.sh /dev/ada0 switch1=$1 ( echo "To: YourEmail@Address.net" echo "Subject: SMART Drive Results for ${switch1}" echo " " ) > /var/cover smartctl -i -H -A -n standby -l error ${switch1} >> /var/cover sendmail -t < /var/cover exit 0 # Set idle mode to so it doesn't spin up. # Options -n standby = Will not let the drive spin up if it's not currently spinning. This means that no data will be present if the drive is not running because it exits out with an error condition. This is nice for those folks who like to use HDD Standby in FreeNAS. # -i = Device Info (Does not force a drive spinup) # -H = Device Health (Forces spinup) # -A = Only Vendor specific SMART attributes (Forces spinup) # -l error = SMART Error Log (Forces spinup)
Here is the more complex script but it brings something extra (not explained like the basic code is in the below text but you should be able to understand it). In the previous script if the drive is in standby you will get a report that doesn't tell you much because the drive is not running. In this script it will periodically poll the hard drive to see if it's out of standby and then generate the report plus it cleans up the report some and more importantly you can run it on all the drives at once (same time period) where as the previous script you could only run a CRON job on one drive, wait a minute and run another CRON job. This is by far the better script of the two.
Code:
#!/usr/local/bin/sh # # Place this in /mnt/pool/scripts # Call: sh esmart.sh /dev/ada0 # switch1 is the drive to check (passed parameter) switch1=$1 # This will use the characters after "/dev/" for the temp file names. # Example: /dev/ada0 becomes coverada0 or cover0ada0 or cover1ada0 # This needs to be done to keep multiple jobs from using the same files. drv=`echo $switch1 | cut -c6-` # Variable just so we can add a note that the drive was asleep when the # application started but is now awake. c=0 # Process to run our check on the drive chkdrive() { smartctl -H -n standby -l error ${switch1} > /var/cover0${drv} } ( echo "To: youremail@address.net" echo "Subject: SMART Drive Results for ${switch1}" echo " " ) > /var/cover${drv} chkdrive while [ $? != "0" ] do # Pause the checking of the drive to about once a minute if the drive is not running. sleep 59 c=1 chkdrive done if [ $c -eq 1 ] then echo "THE DRIVE WAS ASLEEP AND JUST WOKE UP" >> /var/cover${drv} fi # These lines remove the automatic Branding lines sed -e '1d' /var/cover0${drv} > /var/cover1${drv} sed -e '1d' /var/cover1${drv} > /var/cover0${drv} sed -e '1d' /var/cover0${drv} > /var/cover1${drv} sed -e '1d' /var/cover1${drv} > /var/cover0${drv} cat /var/cover0${drv} >> /var/cover${drv} sendmail -t < /var/cover${drv} # Cleanup our trash rm /var/cover${drv} rm /var/cover0${drv} rm /var/cover1${drv} exit 0 # Set idle mode to so it doesn't spin up. # Options # -n standby (Remove this to force a spinup) # -i = Device Info # -H = Device Health # -A = Only Vendor specific SMART attributes # -l error = SMART Error Log
7) Edit youremail@address.net to reflect the email address you desire the report to be sent.
8) You can edit more of the script if you like but you can stop here and lets save this script, Press Escape and save it.
9) Test Run the script by typing 'sh esmart.sh /dev/ada0' NOTE: /dev/ada0 needs to be changed to your drive path. Depending on the drive adapter it could be different.
10) Wait a few seconds and check your email.
Code:
cd /etc cp /conf/base/etc/esmart.sh .
Now let me explain this script so you can make changes to it if you like.
The first few lines define this as a script and tell you how to call this script.
Next we assign variable switch1 for use in the commands.
Next is the code within the parentheses which define the email header and creates the file cover in the RAM based area /var to keep the hard drives from being accessed.
Code:
#!/usr/local/bin/sh # # Place this in /mnt/pool/scripts # Call: sh esmart.sh /dev/ada0 # $1 is the command line variable /dev/ada0 in this example switch1=$1 ( echo "To: YourEmail@Address.net" echo "Subject: SMART Drive Results for ${switch1}" echo " " ) > /var/cover
The key line in the script is:
Code:
smartctl -i -H -A -n standby -l error ${switch1} >> /var/cover
This does all the real work and it will collect the data on the drive specified in switch1. The results will be added to the file cover. If the drive is not spinning then you will get an email stating the drive is in Standby and it exited. You get no data. This is fine for most people who want to minimize spinning up thier hard drives but if you really want the data everytime you run this script, remove the '-n standby' portion.
This section takes the file we created called cover and sends it via the sendmail application.
Code:
sendmail -t < /var/cover exit 0
Now we will create a CRON so this script runs once a day, you can chose how often you want it to run.
12) Open FreeNAS GUI
13) On left side window click on System, Cron Jobs, Add Cron Job
14) Use the following settings: (You may set the time intervals to whatever you desire)
User: root
Command: sh /mnt/pool/scripts/esmart.sh /dev/ada0
Description: ada0 SMART Results
Minute: Each selected minute: 01
Hour: Each selected hour: 01 (checking at 1 AM)
Day of month: Every N day of month: 1
Leave the rest at the default of all checked and click OK.
15) Add additional Cron Jobs for each additional drive you have.
16) Sit back and watch the reports come in.
If you would rather just have one command to check all the drives, here is a script to check 4 drives and you can modify it as you see fit.
Code:
#!/usr/local/bin/sh # # Place this in /mnt/pool/scripts # Call: sh esmart.sh ( echo "To: YourEmail@Address.net" echo "Subject: SMART Drive Results for all drives" echo " " ) > /var/cover smartctl -i -H -A -n standby -l error /dev/ada0 >> /var/cover smartctl -i -H -A -n standby -l error /dev/ada1 >> /var/cover smartctl -i -H -A -n standby -l error /dev/ada2 >> /var/cover smartctl -i -H -A -n standby -l error /dev/ada3 >> /var/cover sendmail -t < /var/cover exit 0 # Set idle mode to so it doesn't spin up. # Options -n standby # -i = Device Info # -H = Device Health # -A = Only Vendor specific SMART attributes # -l error = SMART Error Log
Again, the '-n standby' will cause an issue at the point where a drive not spinning is encountered. Since I have a single pool of 4 drives, should my first drive exit due to not spinning, I can safely assume my other drives are not spinning either since I have the same HDD Standby (in FreeNAS GUI) settings for each.
-Mark
Last edited: