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

Bidule0hm

Server Electronics Sorcerer
Joined
Aug 5, 2013
Messages
3,710
@Bidule0hm

Thank you for these scripts. I had to make minor change in your zpool report script. There is no "-p" option and need to remove percent sign


Code:
used=`zpool list -H -o capacity ${pool} | cut -d'%' -f1`

Hmm... I'll need to check that, maybe a recent update broke this line.

NB: sorry for the delay, I was on vacation.
 

Bidule0hm

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

ethereal

Guru
Joined
Sep 10, 2012
Messages
762
Thanks a lot !

i am a complete idiot but i got your script for cpu and hdd temperatures working
 

Bidule0hm

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

ethereal

Guru
Joined
Sep 10, 2012
Messages
762
i tried the smart script but i got errors if anybody will help that will be great

this is the script i am using http://pastebin.com/rK2WGNE5

[root@freenas] ~# ./scripts/smart.sh
./scripts/smart.sh: +------+---------------+----+-----+-----+-----+-------+-------+--------+------+----------+------+-------+: not found
./scripts/smart.sh: +------+---------------+----+-----+-----+-----+-------+-------+--------+------+----------+------+-------+: not found
awk: no variable name

./scripts/smart.sh: -v: not found
awk: no variable name

./scripts/smart.sh: -v: not found
awk: no variable name

./scripts/smart.sh: -v: not found
awk: no variable name

./scripts/smart.sh: -v: not found
awk: no variable name

./scripts/smart.sh: -v: not found
awk: no variable name

./scripts/smart.sh: -v: not found
awk: no variable name

./scripts/smart.sh: -v: not found
awk: no variable name

./scripts/smart.sh: -v: not found
./scripts/smart.sh: +------+---------------+----+-----+-----+-----+-------+-------+--------+------+----------+------+-------+: not found
awk: syntax error at source line 2
context is
>>> $3, <<<
awk: illegal statement at source line 2
usage: awk [-F fs] [-v var=value] [-f progfile | 'prog'] [file ...]
./scripts/smart.sh: {print $3}: not found
awk: syntax error at source line 2
context is
>>> $3, <<<
awk: illegal statement at source line 2
usage: awk [-F fs] [-v var=value] [-f progfile | 'prog'] [file ...]
./scripts/smart.sh: {print $3}: not found
awk: syntax error at source line 2
context is
>>> $3, <<<
awk: illegal statement at source line 2
usage: awk [-F fs] [-v var=value] [-f progfile | 'prog'] [file ...]
./scripts/smart.sh: {print $3}: not found
awk: syntax error at source line 2
context is
>>> $3, <<<
awk: illegal statement at source line 2
usage: awk [-F fs] [-v var=value] [-f progfile | 'prog'] [file ...]
./scripts/smart.sh: {print $3}: not found
awk: syntax error at source line 2
context is
>>> $3, <<<
awk: illegal statement at source line 2
usage: awk [-F fs] [-v var=value] [-f progfile | 'prog'] [file ...]
./scripts/smart.sh: {print $3}: not found
awk: syntax error at source line 2
context is
>>> $3, <<<
awk: illegal statement at source line 2
usage: awk [-F fs] [-v var=value] [-f progfile | 'prog'] [file ...]
./scripts/smart.sh: {print $3}: not found
awk: syntax error at source line 2
context is
>>> $3, <<<
awk: illegal statement at source line 2
usage: awk [-F fs] [-v var=value] [-f progfile | 'prog'] [file ...]
./scripts/smart.sh: {print $3}: not found
awk: syntax error at source line 2
context is
>>> $3, <<<
awk: illegal statement at source line 2
usage: awk [-F fs] [-v var=value] [-f progfile | 'prog'] [file ...]
./scripts/smart.sh: {print $3}: not found
 

Bidule0hm

Server Electronics Sorcerer
Joined
Aug 5, 2013
Messages
3,710
What editor you've pasted the script in? because a lot of lines are broken, that's why there is a ton of syntax errors.
 

ethereal

Guru
Joined
Sep 10, 2012
Messages
762
i copied from your pastebin page and right clicked in nano
 

Bidule0hm

Server Electronics Sorcerer
Joined
Aug 5, 2013
Messages
3,710
Ok.

Did you use the GUI built-in shell? or you've SSH'd to the NAS?
 

ethereal

Guru
Joined
Sep 10, 2012
Messages
762
i knew i missed a step out - i used putty and ssh'd to freenas
 

Bidule0hm

Server Electronics Sorcerer
Joined
Aug 5, 2013
Messages
3,710
So you used everything I recommended and still have a problem, well...

I wonder, did you put the SSH window in full screen mode? because if it's too small it's probably why some lines got broken.

If you know how to do it you can put the script in a text file on one of your shares on the client side and then copy it to where you want it in a SSH session ;)
 

ethereal

Guru
Joined
Sep 10, 2012
Messages
762
i was a good boy and followed all your instructions :)

i didn't put it in full screen mode - i redid the script in full screen mode and now it works perfectly

thanks again
 

Bidule0hm

Server Electronics Sorcerer
Joined
Aug 5, 2013
Messages
3,710
Ok, I'll add that to the recommendations ;)

You're welcome :)
 

Ruff.Hi

Patron
Joined
Apr 21, 2015
Messages
271
One observation (I think I have this right) ... the CPU temps script reports the current temperatures. I believe that the HDD temps are plucked from the smartctl info and that they are static (ie according to the last time a short or long SMART test was run). Is there a way of getting the current temperatures without having to (re)run a SMART test?

I was running a scrub this morning and the CPU temp email just happened to kick off while the scrub was on / occuring. Temps were about 4C or 5C higher than usual.

While I have you here ... can script's be batched / have subroutines? I find myself copying the email code into various scripts and would like to pull it all out into a subroutine (or similar) ... then just reference the subroutine with suitable parameters. If it can be done, just say 'YES' and I will investigate. If you know it is difficult, then some hints re what to search for would be helpful.

If you know how to do it you can put the script in a text file on one of your shares on the client side and then copy it to where you want it in a SSH session ;)

I've wondered about this ... now that I know it is possible, I will do some sleuthing to find out how to do this.
 

Bidule0hm

Server Electronics Sorcerer
Joined
Aug 5, 2013
Messages
3,710
The temps are definitely not static. Just yesterday I've done some thermal testing and to see what I wanted to see I logged the temps every minute for something like 2 hours and the temps have clearly changed. However the drives usually have a very high thermal inertia (because it's a block of metal after all) so the temps will not change by 10 °C in a minute (as an aside it's bad for the drive life to have big changes of temp in short periods of time) especially if the server is in an air-conditioned room for example ;)

I think it's possible. IIRC you can put the code in a function and this function in a separate script, then you can include/import this script in the others scripts and call the function in them. But keep in mind that they are monitoring scripts and they should not fail so it's probably not a good idea to add a big layer of complexity just to save a few lines.
 

Ruff.Hi

Patron
Joined
Apr 21, 2015
Messages
271
The temps are definitely not static.

Really? I'll review my emails and see if I can see any temp change that is independent of a SMART run.

I think it's possible. IIRC you can put the code in a function and this function in a separate script, then you can include/import this script in the others scripts and call the function in them. But keep in mind that they are monitoring scripts and they should not fail so it's probably not a good idea to add a big layer of complexity just to save a few lines.

Good point ... I will test this with some non-important, trivial, redundant script.
 

cyberjock

Inactive Account
Joined
Mar 25, 2012
Messages
19,526
Really? I'll review my emails and see if I can see any temp change that is independent of a SMART run.

Really! You can even see what the hard drive itself has logged with smartctl -x /dev/blah.
 

Ruff.Hi

Patron
Joined
Apr 21, 2015
Messages
271
You can even see what the hard drive itself has logged with smartctl -x /dev/blah.

Thanks cyberjock. I knew about the '-X' switch but hadn't seen the '-x' one. A bit of googling tells me it just dumps all of the SMART info on the drive. I'll fish through some output.


I thought I should clarify my 'Really?' as the written word is sometimes poor at translating meaning. Not saying that you didn't understand. Or that you did. Bah!

I didn't mean 'Really?' as in 'I don't believe you'.
The one where the person bunches their eyebrows together and slightly leans forward.

I meant 'Really?' as in 'Now that is interesting ... and opens up some avenues of research'.
The one where the person looks skyward and draws out the the 'Re'.
 

cyberjock

Inactive Account
Joined
Mar 25, 2012
Messages
19,526
I didn't mean 'Really?' as in 'I don't believe you'.
The one where the person bunches their eyebrows together and slightly leans forward.

I meant 'Really?' as in 'Now that is interesting ... and opens up some avenues of research'.
The one where the person looks skyward and draws out the the 'Re'.

And that's exactly how I took it to. I thought it was cute, so I stole it for myself. :)
 

cyberjock

Inactive Account
Joined
Mar 25, 2012
Messages
19,526
For the record, I'm not a fan of -x. I hate seeing people ask for it because it dumps a bunch of stuff that is basically unintelligible to us mere mortals unless you happen to have access to OEM information so you can interpret the data. :/

For me, it's -a or bust as it "just works" and gives me the exact info I want. I've only wanted -x once, and that was because someone had cooked their drive and wanted to see if the hard drive knew for how long it was cooked.
 
Top