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

Bill McCormick

Explorer
Joined
Oct 3, 2015
Messages
68
I got the scripts working for my /dev/ada drive, but I'll need to make a change to get the /dev/pass drives working.

Probably the easiest thing to do is change smartctl -A -i -v 7,hex48 /dev/"$drive" to smartctl -A -i -v 7,hex48 "$drive" and include the complete device name and extra params in the $drives variable.
... that's going to be ugly. Need to find a different way. It'd be easy in Perl.
 

Bidule0hm

Server Electronics Sorcerer
Joined
Aug 5, 2013
Messages
3,710
I don't know, I never saw /dev/pass for drives.

Do it in Perl if you want but I can't help, sorry.
 

joeschmuck

Old Man
Moderator
Joined
May 28, 2011
Messages
10,996
It'd be easy in Perl.
If you figure a way to do it in Perl then I would recommend you create a new thread and tell everyone what the process involves and the results. Just maybe it could be useful for more than SMART data results for some people. I myself haven't a clue about Perl but I'd learn if it provided some advantage.
 

Bidule0hm

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

bestboy

Contributor
Joined
Jun 8, 2014
Messages
198
Just want to drop in and say thanks for the scripts.

I also found a small point for improvement in the CPU/HD temperature script on setting it up. Instead of hard-coding the number of CPU cores to query the temperature for, we could use sysctl hw.ncpu
Code:
 ### Parameters ###
    cores=$(sysctl hw.ncpu | cut -c10)
 

Bidule0hm

Server Electronics Sorcerer
Joined
Aug 5, 2013
Messages
3,710
Good idea, thanks ;)

I'll implement it asap.
 

R.G.

Explorer
Joined
Sep 11, 2011
Messages
96
Let me add to the chorus of "Thank You!" for the scripts. Big help.

If I may suggest one extension that's useful for when you're debugging issues with a NAS - I find that the most mysterious issues are thermal. Something works well until it gets too hot. Having the trail of temp data included in a file for download is really useful, but most of the time, it's just data to be ignored - until you really, really need it. Sure big files are easy to keep, and bits are (almost!) free, but it occurred to me that since my NAS is quite lightly loaded most of the time, all but scrubs and backups, it would be useful to have the system pre-sift out a lot of the chaff.

My original thought was to have the system look at whether a scrub was running or not, and while it was running save back disk and cpu temps only then. Disks and CPUs generate heat selectively when they're being exercised hard, and scrubs are about as hard as it gets, and go on for thermally-significant times.

For a system with a light system load, it might make sense for the system to
- check fairly frequently ( and adjustably ) for whether certain tasks were running, like backups to another pools and scrubs
- check temps (or whatever else was useful information) and tuck that into a file either at a selectable more frequent interval or only when the desired measurement was above some level. Back off on the more-frequency monitoring and filing when the monitored event ends

For instance, my disks never get over about 36C unless a scrub is running, at least that I can tell. But I occasionally get temps to 40-41C. I'd be interested to know how long into a scrub it takes for temps to rise per degree when a scub is running. That lets me make a good guess at whether the fans are running, the air filters are clogged, and whether they get a lot hotter than 41C when I don't happen to be watching them.

I'll go and hack on the scripts, but scripts are not my forte. :)

It's really good when your systems can tell you "Boss! Boss! I got heartburn!"
 

Bidule0hm

Server Electronics Sorcerer
Joined
Aug 5, 2013
Messages
3,710
As you know when such tasks are executed you just need to add a CRON task to execute the script at the same time as the other tasks ;)

You may want to add a loop with a delay of 10 min for example to record the temps more than one time.

If you want the output in a file then just redirect it to a file: /example/script.sh >> /example/temp_log.txt

And if you want to add the date and time before each section then do this: date >> /example/temp_log.txt; /example/script.sh >> /example/temp_log.txt
 

ChiknNutz

Patron
Joined
Nov 6, 2015
Messages
217
Just wanted to thank you for an excellent tutorial. I was able to set this up in just a few minutes time. I modified the SMART script to use the adaptive script, awesome BTW! One thing I noticed is that on the last two of my drive names, there is a question mark ? after the name. Any idea why that might be? I do know that because of my mobo, the first four are SATA 6.0Gb/s and the last two are 3.0Gb/s. That's the only difference I know of.

One point I'd like to make, the output email is almost completely useless when viewed on a smartphone (iPhone 6 in my case). I have both the original script you based yours off of running too (started with that one) and it suffers from the same formatting issues. Not sure if there is a way to make these smartphone friendly, similar to how adaptive website are done.

Code:
########## SMART status report summary for all drives ##########

+------+---------------+----+-----+-----+-----+-------+-------+--------+------+------+------+-------+----+
|Device|Serial         |Temp|Power|Start|Spin |ReAlloc|Current|Offline |UDMA  |Seek  |High  |Command|Last|
|      |               |    |On   |Stop |Retry|Sectors|Pending|Uncorrec|CRC   |Errors|Fly   |Timeout|Test|
|      |               |    |Hours|Count|Count|       |Sectors|Sectors |Errors|      |Writes|Count  |Age |
+------+---------------+----+-----+-----+-----+-------+-------+--------+------+------+------+-------+----+
|ada0  |W6A0W76W       | 27 |  304|   10|    0|      0|      0|       0|     0|     0|     0|      0|   1|
|ada1  |W6A0W7HF       | 25 |  303|    9|    0|      0|      0|       0|     0|     0|     0|      0|   1|
|ada2  |W6A0W6YC       | 26 |  303|    9|    0|      0|      0|       0|     0|     0|     1|      0|   1|
|ada3  |W6A0W713       | 28 |  303|    9|    0|      0|      0|       0|     0|     0|     1|      0|   1|
|ada4 ?|W6A0W7DD       | 29 |  183|    1|    0|      0|      0|       0|     0|     0|     0|      0|   2|
|ada5 ?|W6A0W76L       | 27 |  183|    1|    0|      0|      0|       0|     0|     0|     2|      0|   2|
+------+---------------+----+-----+-----+-----+-------+-------+--------+------+------+------+-------+----+
 

Bidule0hm

Server Electronics Sorcerer
Joined
Aug 5, 2013
Messages
3,710
Thanks :)

That's because the Last Test Age value is over 1 (you can change the threshold at the top of the script if you want), the question mark is the warning symbol and the critical symbol is the exclamation mark (you can change them a the top of the script too), it's here to draw your attention on a possible problem ;)

I never intended to make the email smartphone compatible and I don't think I can anyway as it's ASCII Art. The output you posted looks perfect but I use a PC. Can you post a screenshot so I can see what the problem is?
 

ChiknNutz

Patron
Joined
Nov 6, 2015
Messages
217
It's not that is a problem so much as it just forces you to view it on a computer. With so many of us using smart devices, just would be nice to be able to easily view the information on a phone. Here is a screenshot it took from my phone.
 

Attachments

  • image.png
    image.png
    384.8 KB · Views: 374

Bidule0hm

Server Electronics Sorcerer
Joined
Aug 5, 2013
Messages
3,710
Ok, I see. Can you tell your mail client to not wrap the lines if they are too long? (so you'll need to scroll but at least the table isn't destroyed)

Or maybe if you turn the smartphone horizontally and you zoom out a bit you can see the whole table.

In pure theory I can do a mobile version of the script but I don't think I'll do it just because my free time is a negative value currently... :p however you can always do it yourself if you want. You need to modify the table so it'll be sliced in 3 or 4 parts so you can output them one below the other. It's not complicated but it's a somewhat long process.

Edit: I have a very good idea (yeah, it took me some time to have one...) --> as the email is already a html email I can probably just add a fixed width or horizontally scrollable div. I'll test that asap ;)
 
Last edited:

Bidule0hm

Server Electronics Sorcerer
Joined
Aug 5, 2013
Messages
3,710
Yep, and in fact I wanted to say "fixed width or horizontally scrollable div".
 

anodos

Sambassador
iXsystems
Joined
Mar 6, 2014
Messages
9,553
Ok, I see. Can you tell your mail client to not wrap the lines if they are too long? (so you'll need to scroll but at least the table isn't destroyed)

Or maybe if you turn the smartphone horizontally and you zoom out a bit you can see the whole table.

In pure theory I can do a mobile version of the script but I don't think I'll do it just because my free time is a negative value currently... :p however you can always do it yourself if you want. You need to modify the table so it'll be sliced in 3 or 4 parts so you can output them one below the other. It's not complicated but it's a somewhat long process.

Edit: I have a very good idea (yeah, it took me some time to have one...): as the email is already a html email I can probably just add a fixed width horizontally scrollable div. I'll test that asap ;)

If people are unhappy with your ASCII art, you should use html frames to format it for their fancy-pants smart thingies. That'll show them!
 

gabeszphoto

Dabbler
Joined
Aug 30, 2014
Messages
14
Hello All,
I would like to write a simple script to restart the Transmission service in a scheduled cron job because it stops randomly.. I written a script but unfortunately it stops after the first line.. I attached my code, please help me! Thank you!

Code:
#! /bin/sh
echo "Transmission Restarter Script"
jexec 4 csh

service transmission restart

echo "Transmission is restarted..."


and this is the answer when I try to run it..

Code:
[root@OurNAS] ~# bash /mnt/OurNAS/gabor/transmission_restart.sh
Transmission Restarter Script
root@transmission_1:/ #
root@transmission_1:/ # exit
exit
transmission does not exist in /etc/rc.d or the local startup
directories (/etc/ix.rc.d /usr/local/etc/rc.d)
Transmission is restarted...
 

Bidule0hm

Server Electronics Sorcerer
Joined
Aug 5, 2013
Messages
3,710
You should have started a new thread and not in this section, please do that the next time, thanks.

First thing: it's better to use the jail name after jexec because I've seen jail id changes without warning.

Second thing: just use jexec 4 service transmission restart ;)

Third thing: be sure "transmission" is the right service name by executing this command manually in the jail: service transmission restart and see if it fails or not.
 

gabeszphoto

Dabbler
Joined
Aug 30, 2014
Messages
14
You should have started a new thread and not in this section, please do that the next time, thanks.

First thing: it's better to use the jail name after jexec because I've seen jail id changes without warning.

Second thing: just use jexec 4 service transmission restart ;)

Third thing: be sure "transmission" is the right service name by executing this command manually in the jail: service transmission restart and see if it fails or not.

Thanks for the fast answer and help, now it works perfectly! :) This is the right code:

Code:
#! /bin/sh
echo "Transmission Restarter Script"
jexec transmission_1 service transmission restart

echo "Transmission is restarted..."
 

Bidule0hm

Server Electronics Sorcerer
Joined
Aug 5, 2013
Messages
3,710
Perfect, you're welcome ;)
 
Top