Closed hexadecagram closed 7 years ago
Cool. Could you explain the awk code?
BEGIN { attr=0; temp=0 }
$1 ~ /19[04]/ { if (attr != "194") { attr=$1; temp=$10 } }
END { print temp }
It looks like it operates on lines beginning with 190 or 194, but I'm not sure what the conditional is doing.
It's a tricky bit of code and yeah it's not completely obvious as to how it works. You could massage the following into a comment before you commit if you like.
You're correct. The second line of the AWK program matches the first field of the smartctl output if it is 190 or 194. We have to consider 5 cases with the program:
BEGIN { attr=0; temp=-273.15; }
END { if (temp != "-273.15") print temp; }
We should use absolute zero (-273.15 degrees Celsius) because it would be impossible for a drive to be that cold. But in Antarctica? It could be really cold.Ahh, ok. So it's setting the temperature from matching lines, giving precedence to attribute 190. When I tried it, it output a temperature of zero for my usb non-SMART drive. I think that if it doesn't find a match, the output is the default value of temp
which is 0. I tried setting it -99 (which should never be a valid temperature) and catching that in the loop which worked, but I'm not sure if you can think of a better method:
BEGIN { attr=0; temp=-99 }
$1 ~ /19[04]/ { if (attr != "194") { attr=$1; temp=$10 } }
END { print temp }
if ! [ "$DevTemp" == "-99" ]; then
drivedevs="${drivedevs} ${i}"
[ -n "$verbose" ] && echo "drivedevs: ${drivedevs}"
fi
I edited my comment with a solution because I thought of exactly that after the fact. ;-)
Note that I also changed the END block rather than modify the outer bash script, as you did. Would work either way, but IMO having it in the AWK program makes it cleaner and more obvious without having to explain it in a comment.
Cool, I agree that having it in the awk script is cleaner. I'll merge this and add the change. I'll probably stick with the -99 rather than -273.15 since it's a bit easier to read/understand and I can't imagine any FreeNAS server drive being either temperature while being turned on. :)
That's probably me just letting my FreeBSD side show through. Very scientifically-minded bunch. But you're right, it's not likely that they use FreeNAS on the space shuttle. And even if they did, hey, it's open source.
Modified data collection, graph generation, and format scripts to better accommodate non-S.M.A.R.T. drives, min and max safe temperature limits for mechanical drives, and a wider overall temperature range, and to produce accurate verbose output, and create graphs with more readable curves.