[plug] More bash - drive-age.sh

Brad Campbell brad at fnarfbargle.com
Tue May 9 11:05:24 AWST 2017


On 09/05/17 01:12, David Godfrey wrote:
> Hi Brad,
>
> I've done up a pure bash (other than smartctl and sudo) version of this
> with a few extra features.
>
> You can download it from http://www.sbts.com.au/files/drive-age.sh
>
> But here it is in text form


So there are a couple of problems.
First the version lined above has a leftover in it :

srv:~# bash ./drive-age.sh
./drive-age.sh: line 34: unexpected argument `newline' to conditional 
unary operator
./drive-age.sh: line 34: syntax error near `-n'
./drive-age.sh: line 34: `        [[ -n'

Once that is gone we get the following :

srv:~# ./drive-age.sh -L -s
     WARNING: This is an old version of this script.
     current versions can be found at
     https://github.com/sbts/misc-scripts

Scanning drives ......................... : Done
./drive-age.sh: line 116: <= 1446 : syntax error: operand expected 
(error token is "<= 1446 ")
./drive-age.sh: line 116: <= 1446 : syntax error: operand expected 
(error token is "<= 1446 ")
./drive-age.sh: line 116: <= 1446 : syntax error: operand expected 
(error token is "<= 1446 ")
./drive-age.sh: line 116: <= 1487 : syntax error: operand expected 
(error token is "<= 1487 ")
./drive-age.sh: line 116: <= 1487 : syntax error: operand expected 
(error token is "<= 1487 ")
./drive-age.sh: line 116: <= 1487 : syntax error: operand expected 
(error token is "<= 1487 ")
./drive-age.sh: line 116: <= 7043 : syntax error: operand expected 
(error token is "<= 7043 ")
./drive-age.sh: line 116: <= 7043 : syntax error: operand expected 
(error token is "<= 7043 ")
./drive-age.sh: line 116: <= 7043 : syntax error: operand expected 
(error token is "<= 7043 ")
./drive-age.sh: line 116: <= 7043 : syntax error: operand expected 
(error token is "<= 7043 ")
./drive-age.sh: line 116: <= 7043 : syntax error: operand expected 
(error token is "<= 7043 ")
./drive-age.sh: line 116: <= 7043 : syntax error: operand expected 
(error token is "<= 7043 ")
./drive-age.sh: line 116: <= 26559 : syntax error: operand expected 
(error token is "<= 26559 ")
./drive-age.sh: line 116: <= 26559 : syntax error: operand expected 
(error token is "<= 26559 ")
./drive-age.sh: line 116: <= 26559 : syntax error: operand expected 
(error token is "<= 26559 ")
./drive-age.sh: line 116: <= 26559 : syntax error: operand expected 
(error token is "<= 26559 ")
./drive-age.sh: line 116: <= 26559 : syntax error: operand expected 
(error token is "<= 26559 ")
./drive-age.sh: line 116: <= 26559 : syntax error: operand expected 
(error token is "<= 26559 ")
./drive-age.sh: line 116: <= 26559 : syntax error: operand expected 
(error token is "<= 26559 ")
./drive-age.sh: line 116: <= 26559 : syntax error: operand expected 
(error token is "<= 26559 ")
./drive-age.sh: line 116: <= 26559 : syntax error: operand expected 
(error token is "<= 26559 ")
./drive-age.sh: line 116: <= 33447 : syntax error: operand expected 
(error token is "<= 33447 ")
./drive-age.sh: line 116: <= 33447 : syntax error: operand expected 
(error token is "<= 33447 ")
./drive-age.sh: line 116: <= 33447 : syntax error: operand expected 
(error token is "<= 33447 ")
./drive-age.sh: line 116: <= 37741 : syntax error: operand expected 
(error token is "<= 37741 ")
./drive-age.sh: line 116: <= 37741 : syntax error: operand expected 
(error token is "<= 37741 ")
./drive-age.sh: line 116: <= 37741 : syntax error: operand expected 
(error token is "<= 37741 ")
./drive-age.sh: line 116: <= 37741 : syntax error: operand expected 
(error token is "<= 37741 ")
./drive-age.sh: line 116: <= 37741 : syntax error: operand expected 
(error token is "<= 37741 ")
./drive-age.sh: line 116: <= 37741 : syntax error: operand expected 
(error token is "<= 37741 ")
./drive-age.sh: line 116: <= 39875 : syntax error: operand expected 
(error token is "<= 39875 ")
./drive-age.sh: line 116: <= 39875 : syntax error: operand expected 
(error token is "<= 39875 ")
./drive-age.sh: line 116: <= 39875 : syntax error: operand expected 
(error token is "<= 39875 ")
./drive-age.sh: line 116: <= 53221 : syntax error: operand expected 
(error token is "<= 53221 ")
./drive-age.sh: line 116: <= 53221 : syntax error: operand expected 
(error token is "<= 53221 ")
./drive-age.sh: line 116: <= 53221 : syntax error: operand expected 
(error token is "<= 53221 ")
./drive-age.sh: line 116: <= 53221 : syntax error: operand expected 
(error token is "<= 53221 ")
./drive-age.sh: line 116: <= 53221 : syntax error: operand expected 
(error token is "<= 53221 ")
./drive-age.sh: line 116: <= 53221 : syntax error: operand expected 
(error token is "<= 53221 ")
./drive-age.sh: line 116: <= 53222 : syntax error: operand expected 
(error token is "<= 53222 ")
./drive-age.sh: line 116: <= 53222 : syntax error: operand expected 
(error token is "<= 53222 ")
./drive-age.sh: line 116: <= 53222 : syntax error: operand expected 
(error token is "<= 53222 ")
./drive-age.sh: line 116: <= 53222 : syntax error: operand expected 
(error token is "<= 53222 ")
./drive-age.sh: line 116: <= 53222 : syntax error: operand expected 
(error token is "<= 53222 ")
./drive-age.sh: line 116: <= 53222 : syntax error: operand expected 
(error token is "<= 53222 ")
./drive-age.sh: line 116: <= 53223 : syntax error: operand expected 
(error token is "<= 53223 ")
./drive-age.sh: line 116: <= 53223 : syntax error: operand expected 
(error token is "<= 53223 ")
./drive-age.sh: line 116: <= 53223 : syntax error: operand expected 
(error token is "<= 53223 ")
./drive-age.sh: line 116: <= 53224 : syntax error: operand expected 
(error token is "<= 53224 ")
./drive-age.sh: line 116: <= 53224 : syntax error: operand expected 
(error token is "<= 53224 ")
./drive-age.sh: line 116: <= 53224 : syntax error: operand expected 
(error token is "<= 53224 ")
./drive-age.sh: line 116: <= 53254 : syntax error: operand expected 
(error token is "<= 53254 ")
./drive-age.sh: line 116: <= 53254 : syntax error: operand expected 
(error token is "<= 53254 ")
./drive-age.sh: line 116: <= 53254 : syntax error: operand expected 
(error token is "<= 53254 ")
./drive-age.sh: line 116: <=  : syntax error: operand expected (error 
token is "<=  ")
./drive-age.sh: line 116: <=  : syntax error: operand expected (error 
token is "<=  ")
./drive-age.sh: line 116: <=  : syntax error: operand expected (error 
token is "<=  ")
./drive-age.sh: line 116: <=  : syntax error: operand expected (error 
token is "<=  ")
./drive-age.sh: line 116: <=  : syntax error: operand expected (error 
token is "<=  ")
./drive-age.sh: line 116: <=  : syntax error: operand expected (error 
token is "<=  ")
/dev/sda - WDC WDS120G1G0A-00SS50         -  0 Years  60 Days  6 Hours - 
Temperature (min/max)
/dev/sdb - GeIL ZENITH R3_120GB           -  0 Years  61 Days 23 Hours - 
Temperature (min/max) 0/41 Celsius
/dev/sdy - WDC WD60EFRX-68L0BN1           -  0 Years 293 Days  9 Hours - 
Temperature (min/max) 19/37 Celsius
/dev/sdx - WDC WD10EFRX-68FYTN0           -  0 Years 293 Days 10 Hours - 
Temperature (min/max) 17/34 Celsius
/dev/sdv - WDC WD10EFRX-68FYTN0           -  0 Years 293 Days 10 Hours - 
Temperature (min/max) 16/34 Celsius
/dev/sdl - WDC WD20EFRX-68AX9N0           -  3 Years  11 Days 15 Hours - 
Temperature (min/max) 10/43 Celsius
/dev/sdk - WDC WD20EFRX-68AX9N0           -  3 Years  11 Days 15 Hours - 
Temperature (min/max) 9/42 Celsius
/dev/sdh - WDC WD20EFRX-68AX9N0           -  3 Years 298 Days 15 Hours - 
Temperature (min/max) 13/43 Celsius
/dev/sdw - WDC WD20EFRX-68AX9N0           -  3 Years 298 Days 16 Hours - 
Temperature (min/max) 12/43 Celsius
/dev/sdq - WDC WD20EARS-60MVWB0           -  4 Years 112 Days 13 Hours - 
Temperature (min/max) 26/44 Celsius
/dev/sdf - SAMSUNG SSD 830 Series         -  4 Years 201 Days 11 Hours - 
Temperature (min/max)
/dev/sdr - WDC WD20EARS-60MVWB0           -  6 Years  27 Days 13 Hours - 
Temperature (min/max) 26/45 Celsius
/dev/sdi - WDC WD20EARS-60MVWB0           -  6 Years  27 Days 13 Hours - 
Temperature (min/max) 27/44 Celsius
/dev/sdn - WDC WD20EARS-60MVWB0           -  6 Years  27 Days 14 Hours - 
Temperature (min/max) 27/44 Celsius
/dev/sdm - WDC WD20EARS-60MVWB0           -  6 Years  27 Days 14 Hours - 
Temperature (min/max) 26/43 Celsius
/dev/sdo - WDC WD20EARS-60MVWB0           -  6 Years  27 Days 15 Hours - 
Temperature (min/max) 0/44 Celsius
/dev/sdp - WDC WD20EARS-60MVWB0           -  6 Years  27 Days 16 Hours - 
Temperature (min/max) 27/43 Celsius
/dev/sdj - WDC WD20EARS-60MVWB0           -  6 Years  28 Days 22 Hours - 
Temperature (min/max) 27/45 Celsius
/dev/sds - INTEL SSDSC2CT240A3            -  0 Years   0 Days  0 Hours - 
Temperature (min/max) 0/ 0
/dev/sdt - INTEL SSDSC2CT240A3            -  0 Years   0 Days  0 Hours - 
Temperature (min/max) 0/ 0
/dev/sdu - INTEL SSDSC2CT240A3            -  0 Years   0 Days  0 Hours - 
Temperature (min/max) 30/30 Celsius
          -                                -  0 Years   0 Days  0 Hours 
- Temperature (min/max)
          -                                -  0 Years   0 Days  0 Hours 
- Temperature (min/max)
          -                                -  0 Years   0 Days  0 Hours 
- Temperature (min/max)
          -                                -  0 Years   0 Days  0 Hours 
- Temperature (min/max)


It works ok if not sorted.
srv:~# ./drive-age.sh -L
     WARNING: This is an old version of this script.
     current versions can be found at
     https://github.com/sbts/misc-scripts

Scanning drives ......................... : Done
/dev/sda - WDC WDS120G1G0A-00SS50         -  0 Years  60 Days  6 Hours - 
Temperature (min/max)
/dev/sdb - GeIL ZENITH R3_120GB           -  0 Years  61 Days 23 Hours - 
Temperature (min/max) 0/41 Celsius
/dev/sdc - WDC WD20EFRX-68EUZN0           -  1 Years 359 Days  3 Hours - 
Temperature (min/max) 2/41 Celsius
/dev/sdd - WDC WD20EFRX-68EUZN0           -  0 Years 293 Days 11 Hours - 
Temperature (min/max) 18/37 Celsius
/dev/sde - SAMSUNG SSD 830 Series         -  4 Years 201 Days  8 Hours - 
Temperature (min/max)
/dev/sdf - SAMSUNG SSD 830 Series         -  4 Years 201 Days 11 Hours - 
Temperature (min/max)
/dev/sdg - SAMSUNG SSD 830 Series         -  4 Years 201 Days 12 Hours - 
Temperature (min/max)
/dev/sdh - WDC WD20EFRX-68AX9N0           -  3 Years 298 Days 15 Hours - 
Temperature (min/max) 13/43 Celsius
/dev/sdi - WDC WD20EARS-60MVWB0           -  6 Years  27 Days 13 Hours - 
Temperature (min/max) 27/44 Celsius
/dev/sdj - WDC WD20EARS-60MVWB0           -  6 Years  28 Days 22 Hours - 
Temperature (min/max) 27/45 Celsius
/dev/sdk - WDC WD20EFRX-68AX9N0           -  3 Years  11 Days 15 Hours - 
Temperature (min/max) 9/42 Celsius
/dev/sdl - WDC WD20EFRX-68AX9N0           -  3 Years  11 Days 15 Hours - 
Temperature (min/max) 10/43 Celsius
/dev/sdm - WDC WD20EARS-60MVWB0           -  6 Years  27 Days 14 Hours - 
Temperature (min/max) 26/43 Celsius
/dev/sdn - WDC WD20EARS-60MVWB0           -  6 Years  27 Days 14 Hours - 
Temperature (min/max) 27/44 Celsius
/dev/sdo - WDC WD20EARS-60MVWB0           -  6 Years  27 Days 15 Hours - 
Temperature (min/max) 0/44 Celsius
/dev/sdp - WDC WD20EARS-60MVWB0           -  6 Years  27 Days 16 Hours - 
Temperature (min/max) 27/43 Celsius
/dev/sdq - WDC WD20EARS-60MVWB0           -  4 Years 112 Days 13 Hours - 
Temperature (min/max) 26/44 Celsius
/dev/sdr - WDC WD20EARS-60MVWB0           -  6 Years  27 Days 13 Hours - 
Temperature (min/max) 26/45 Celsius
/dev/sds - INTEL SSDSC2CT240A3            -  0 Years   0 Days  0 Hours - 
Temperature (min/max) 0/ 0
/dev/sdt - INTEL SSDSC2CT240A3            -  0 Years   0 Days  0 Hours - 
Temperature (min/max) 0/ 0
/dev/sdu - INTEL SSDSC2CT240A3            -  0 Years   0 Days  0 Hours - 
Temperature (min/max) 30/30 Celsius
/dev/sdv - WDC WD10EFRX-68FYTN0           -  0 Years 293 Days 10 Hours - 
Temperature (min/max) 16/34 Celsius
/dev/sdw - WDC WD20EFRX-68AX9N0           -  3 Years 298 Days 16 Hours - 
Temperature (min/max) 12/43 Celsius
/dev/sdx - WDC WD10EFRX-68FYTN0           -  0 Years 293 Days 10 Hours - 
Temperature (min/max) 17/34 Celsius
/dev/sdy - WDC WD60EFRX-68L0BN1           -  0 Years 293 Days  9 Hours - 
Temperature (min/max) 19/37 Celsius

Notice the Intel SSD's have no time?
There was a good reason for the following  :
	hrs=$(echo "$SMART" | grep Power_On_Hours | awk '{print $8}' | egrep -v 
'[[:alpha:]]')
	[ -z "$hrs" ] && hrs=$(echo "$SMART" | grep 'Power-on Hours' | awk 
'{print $4}')
	[ -z "$hrs" ] && hrs=$(echo "$SMART" | egrep '^# 1' | cut -c 60- | awk 
'{print $1}')


Some drives don't reliably report Power_On_Hours, so you need to try 
Power-on Hours, and if that fails it gets the time from the 1st entry in 
the SMART tests log assuming you do daily SMART tests (if you don't, you 
should). This also covers SAS drives which report completely differently 
again, although I no longer have any in the system to test with.

Relevant bits of the Intel SSD -x output :

   9 Power_On_Hours_and_Msec -O--CK   000   000   000    - 
927819h+58m+45.680s

# 1  Short offline       Self-test routine in progress 10%     33017 
     -

0x01  0x010  4           33024  ---  Power-on Hours

Lots of nice examples in there that don't come up often. Many thanks.

Regards,
Brad



More information about the plug mailing list