Scripts to report SMART, ZPool and UPS status, HDD/CPU T°, HDD identification and backup the config

shnurov

Explorer
Joined
Jul 22, 2015
Messages
74
Tried adding the
sh ./scripts/zpool_status.sh
Failed.
Now trying
./scripts/zpool_status.sh
 

Bidule0hm

Server Electronics Sorcerer
Joined
Aug 5, 2013
Messages
3,710
./ will not work, you need to put the absolute path (/root/... or /mnt/... for example).

Can you post the output of head your_script_file please?
 

Linkman

Patron
Joined
Feb 19, 2015
Messages
219
I'm having a hard time with the cron jobs paths.
I have the scripts created in :

root/scripts/cpu_hdd_temp.sh
Now that's what I wrote in the cron job in the path is :
/root/scripts/cpu_hdd_temp.sh

The e-mail I get is:

Code:
Cron <root@freenas> PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/root/bin" /root/scrips/cpu_hdd_temp.sh > /dev/null

with the body
Code:
/root/scrips/cpu_hdd_temp.sh: not found


Any ideas where I messed up? :(

My first suggestion would be to check spelling. You put the scripts in "/root/scripts/" and the body of the email says "/root/scrips/" where the second one there doesn't have a "t" in scripts.
 

robuyo

Dabbler
Joined
Apr 13, 2015
Messages
11
Really helpful Bidule0hm. I have customized yours and this is what I have.

Daily report about my cpu & hds temps with the UPS status (some custom values).
Weekly report about SMART.
Weekly report about Zpool status with the HDs Device, GPTID, Serial.

Thank you!
 

Bidule0hm

Server Electronics Sorcerer
Joined
Aug 5, 2013
Messages
3,710
You're welcome ;) :)
 

Will Dormann

Explorer
Joined
Feb 10, 2015
Messages
61
Why are there separate scripts for SAS and SATA in the "Display drives identification infos (Device, GPTID, Serial)" section? Wouldn't it be easier to just use "grep -i"?

Also, if you use bash, you can have something like this instead of explicitly enumerating drives:
drives=`echo da{0..7}`
 

Bidule0hm

Server Electronics Sorcerer
Joined
Aug 5, 2013
Messages
3,710
Because the scripts can (and do) evolve so even if I can do one script now I don't know if it would be the case tomorrow.

Yep but I don't want to use bash, I try to make the scripts POSIX compliant so they are robust and reliable (I still need to modify some of them to make them POSIX compliant...) ;)
 

Will Dormann

Explorer
Joined
Feb 10, 2015
Messages
61
Because the scripts can (and do) evolve so even if I can do one script now I don't know if it would be the case tomorrow.

Interesting motivation. Personally, I'd start with one script and only split into two if there were some issue that couldn't be resolved by having a single script. And then consider splitting them into two. However, given the dynamic capabilities that shell scripts can have, I can't fathom what would cause that to be the case.

Anyway, the current scripts don't help for systems that have both SAS and SATA drives. Having the capability split into two distinct scripts to achieve a case insensitive grep is, well, not ideal.
 

Bidule0hm

Server Electronics Sorcerer
Joined
Aug 5, 2013
Messages
3,710
That's an edge case... and you can use both scripts at the same time so I don't see where the problem is. Plus they are pretty much a one time thing, once you've saved your drives identification infos you don't need to execute the script again until you replace a drive.

But, anyway, you know how to make one script so there's really no problem, if you want to merge the two scripts in one then just do it ;)
 

Will Dormann

Explorer
Joined
Feb 10, 2015
Messages
61
Of course I already did that. I just figured that maybe somebody would want to update what's being linked to in this thread.
 

Bidule0hm

Server Electronics Sorcerer
Joined
Aug 5, 2013
Messages
3,710
Ok, no problem ;)
 

Daurtanyn

Dabbler
Joined
Jan 12, 2016
Messages
11
My thanks as well, BiduleOhm

I tried to use your SAS script for "Display drives identification infos (Device, GPTID, Serial)", SAS version. But it didn't work for me because I have SAS drives, but also use multipath. I have modified your version and I'm providing the modified script:
Code:
#!/bin/sh

drives="disk1 disk2 disk3 disk4 disk5 disk6 disk7"

echo ""
echo "+========+============================================+======================+=======+"
echo "| Device | GPTID                                      | Serial               | active|"
echo "+========+============================================+======================+=======+"
for drive in $drives
do
    activedev=`gmultipath getactive ${drive}`
    gptid=`glabel status -s "multipath/${drive}p2" | awk '{print $1}'`
    serial=`smartctl -i /dev/${activedev} | grep "Serial number" | awk '{print $3}'`
    printf "| %-6s | %-42s | %-20s | %-5s |\n" "$drive" "$gptid" "$serial" "$activedev"
    echo "+--------+--------------------------------------------+----------------------+-------+"
done
echo ""


Again, many thanks. And I hope my slight modification will help others.

Here is an example of the output, SN redacted:
Code:
+========+============================================+======================+=======+
| Device | GPTID                                      | Serial               | active|
+========+============================================+======================+=======+
| disk1  | gptid/c1f2fcc4-b868-11e5-8b7b-f46d0428d010 | XXX1K5xx             | da6   |
+--------+--------------------------------------------+----------------------+-------+
| disk2  | gptid/9067d034-b7fd-11e5-93c1-f46d0428d010 | XXX1WDxx00009438Kxxx | da11  |
+--------+--------------------------------------------+----------------------+-------+
| disk3  | gptid/0ecce300-2424-11e4-8980-f46d0428d010 | XXX1WDxx0000C4394xxx | da7   |
+--------+--------------------------------------------+----------------------+-------+
| disk4  | gptid/0f031df2-2424-11e4-8980-f46d0428d010 | XXX1WDxx00009437Jxxx | da9   |
+--------+--------------------------------------------+----------------------+-------+
| disk5  | gptid/0f3b1967-2424-11e4-8980-f46d0428d010 | XXX1WDxx0000C4396xxx | da3   |
+--------+--------------------------------------------+----------------------+-------+
| disk6  | gptid/0f7472dc-2424-11e4-8980-f46d0428d010 | XXX1WDxx0000C4390xxx | da8   |
+--------+--------------------------------------------+----------------------+-------+
| disk7  | gptid/e4eee36e-b824-11e5-882c-f46d0428d010 | XXX1Wxx1000094393xxx | da12  |
+--------+--------------------------------------------+----------------------+-------+
 
Last edited:

Bidule0hm

Server Electronics Sorcerer
Joined
Aug 5, 2013
Messages
3,710
Thanks for this version ;)

Can you provide an example of the output? (you can redact the S/N if you want)
 

Daurtanyn

Dabbler
Joined
Jan 12, 2016
Messages
11
My previous posting has been updated with the output of the script... (SNs redacted).

This version adds the active drive label in the multipath and uses that drive label to determine the serial number via smartctl.

The FreeNAS GUI is nice because it presents the devices using the abstraction "multipath/disk6p2", for example. But the CLI uses the GPTID when listing the volume devices.
Code:
[root@freenas] /# zpool status myvol1
  pool: myvol1
state: ONLINE
  scan: resilvered 239G in 1h8m with 0 errors on Mon Jan 11 00:41:58 2016
config:

        NAME                                            STATE     READ WRITE CKSUM
        myvol1                                          ONLINE       0     0     0
          raidz2-0                                      ONLINE       0     0     0
            gptid/e4eee36e-b824-11e5-882c-f46d0428d010  ONLINE       0     0     0
            gptid/9067d034-b7fd-11e5-93c1-f46d0428d010  ONLINE       0     0     0
            gptid/0ecce300-2424-11e4-8980-f46d0428d010  ONLINE       0     0     0
            gptid/0f031df2-2424-11e4-8980-f46d0428d010  ONLINE       0     0     0
            gptid/0f3b1967-2424-11e4-8980-f46d0428d010  ONLINE       0     0     0
            gptid/0f7472dc-2424-11e4-8980-f46d0428d010  ONLINE       0     0     0

errors: No known data errors


This modified script should be very useful for troubleshooting since it a quick bridge between the abstraction name and the GPTID.
 
Last edited:

Bidule0hm

Server Electronics Sorcerer
Joined
Aug 5, 2013
Messages
3,710
Ok perfect, thanks ;)

I'll add it to the OP as soon as I can :)
 

theshadow27

Cadet
Joined
Jan 14, 2016
Messages
3
Summary: I wrote this quickly to create a persistent record of SMART status in CSV format that could be opened by Excel (for pivot table goodness). It currently tries any valid 'da' and 'ada' devices, but it's easy to change or add more. There's a hook up top to for an easy place to add an SCP, email, etc. command to do something useful with the data.

Script: http://pastebin.com/reUEEsgU
Sample output: http://pastebin.com/8sdAG9Yy
 
Joined
Dec 2, 2015
Messages
730
Summary: I wrote this quickly to create a persistent record of SMART status in CSV format that could be opened by Excel (for pivot table goodness). It currently tries any valid 'da' and 'ada' devices, but it's easy to change or add more. There's a hook up top to for an easy place to add an SCP, email, etc. command to do something useful with the data.

Script: http://pastebin.com/reUEEsgU
Sample output: http://pastebin.com/8sdAG9Yy
This really should be in its own thread. If not, it will escape notice from most new users once there are enough new posts in this thread so your item is no longer on the last page.
 

bmcclure937

Contributor
Joined
Jul 13, 2012
Messages
110
Ok, no problem ;)

OP (@Bidule0hm) - thanks for these useful scripts and nice thread. I had to do a little digging to find this thread to schedule my own scrub of my boot media. It might be useful to include that in your OP.

One question. I am running these scripts on a newly installed FreeNAS. I did not put them on my dataset, rather I made a new directory (scripts) in the root home and created my scripts here.

/root/scripts/

Will this be a safe location for my scripts or can this potentially be overwritten during upgrades of FreeNAS? I was having a hard time finding the appropriate place to create a directory for these scripts.

Thanks Again!
 

Bidule0hm

Server Electronics Sorcerer
Joined
Aug 5, 2013
Messages
3,710
No need for a script to scrub the boot media, you have the GUI feature where you set the interval between scrubs or you can set a CRON task if you want the scrub to be done at the exact same minute the exact same hour the exact same day each time (just set the GUI interval to a higher value than the interval between the CRON task set scrubs) ;)

It'll not be overwritten by updates (from the GUI) but it'll be by upgrades (re-install of the system). I recommend to put them on a dedicated dataset on the safest pool you have (e.g. if you have a mirror and a RAID-Z2 put it on the RAID-Z2) you'll be able to access them with /mnt/your_pool/the_dataset/ ;)
 

bmcclure937

Contributor
Joined
Jul 13, 2012
Messages
110
It'll not be overwritten by updates (from the GUI) but it'll be by upgrades (re-install of the system). I recommend to put them on a dedicated dataset on the safest pool you have (e.g. if you have a mirror and a RAID-Z2 put it on the RAID-Z2) you'll be able to access them with /mnt/your_pool/the_dataset/ ;)

I am running a ZFS mirror. I have heard that keeping the scripts on my pool could potentially cause issues and interfere with S.M.A.R.T and scrubs. Any truth to that or should I create a dataset for the scripts and throw them out there?
 
Top