Advertisement
Guest User

cat -e Script1

a guest
Mar 4th, 2015
445
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.11 KB | None | 0 0
  1.  
  2. [root@Triforce] /mnt/Baldr/bin# cat -e Script1
  3. #!/bin/sh$
  4. $
  5. ### Parameters ###$
  6. logfile="/tmp/smart_report.tmp"$
  7. email="jhavens12@gmail.com"$
  8. subject="SMART Status Report for FreeNAS"$
  9. drives=`sysctl -n kern.disks | awk '{for (i=NF; i!=0 ; i--) print $i }'`$
  10. tempWarn=40$
  11. tempCrit=45$
  12. sectorsCrit=10$
  13. warnSymbol="?"$
  14. critSymbol="!"$
  15. $
  16. ### Set email headers ###$
  17. ($
  18. echo "To: ${email}"$
  19. echo "Subject: ${subject}"$
  20. echo "Content-Type: text/html"$
  21. echo "MIME-Version: 1.0"$
  22. echo -e "\r\n"$
  23. ) > ${logfile}$
  24. $
  25. ### Set email body ###$
  26. echo "<pre style=\"font-size:14px\">" >> ${logfile}$
  27. $
  28. ###### summary ######$
  29. ($
  30. echo ""$
  31. echo "########## SMART status report summary for all drives ##########"$
  32. echo ""$
  33. echo "+------+---------------+----+-----+-----+-----+-------+-------+--------+------+----------+------+-------+"$
  34. echo "|Device|Serial |Temp|Power|Start|Spin |ReAlloc|Current|Offline |Seek |Total |High |Command|"$
  35. echo "| | | |On |Stop |Retry|Sectors|Pending|Uncorrec|Errors|Seeks |Fly |Timeout|"$
  36. echo "| | | |Hours|Count|Count| |Sectors|Sectors | | |Writes|Count |"$
  37. echo "+------+---------------+----+-----+-----+-----+-------+-------+--------+------+----------+------+-------+"$
  38. ) >> ${logfile}$
  39. for drive in $drives$
  40. do$
  41. ($
  42. smartctl -A -i -v 7,hex48 /dev/${drive} | \$
  43. awk -v device=${drive} -v tempWarn=${tempWarn} -v tempCrit=${tempCrit} -v sectorsCrit=${sectorsCrit} -v warnSymbol=${warnSymbol} -v $
  44. critSymbol=${critSymbol} '\$
  45. /Serial Number:/{serial=$3} \$
  46. /Temperature_Celsius/{temp=$10} \$
  47. /Power_On_Hours/{onHours=$10} \$
  48. /Start_Stop_Count/{startStop=$10} \$
  49. /Spin_Retry_Count/{spinRetry=$10} \$
  50. /Reallocated_Sector/{reAlloc=$10} \$
  51. /Current_Pending_Sector/{pending=$10} \$
  52. /Offline_Uncorrectable/{offlineUnc=$10} \$
  53. /Seek_Error_Rate/{seekErrors=("0x" substr($10,3,4));totalSeeks=("0x" substr($10,7))} \$
  54. /High_Fly_Writes/{hiFlyWr=$10} \$
  55. /Command_Timeout/{cmdTimeout=$10} \$
  56. END {$
  57. if (temp > tempCrit || reAlloc > sectorsCrit || pending > sectorsCrit || offlineUnc > sectorsCrit) device=device " " critSymbol;$
  58. else if (temp > tempWarn || reAlloc > 0 || pending > 0 || offlineUnc > 0) device=device " " warnSymbol;$
  59. seekErrors=sprintf("%d", seekErrors);$
  60. totalSeeks=sprintf("%d", totalSeeks);$
  61. if (totalSeeks == "0") {$
  62. seekErrors="N/A";$
  63. totalSeeks="N/A";$
  64. }$
  65. if (hiFlyWr == "") hiFlyWr="N/A";$
  66. if (cmdTimeout == "") cmdTimeout="N/A";$
  67. printf "|%-6s|%-15s| %s |%5s|%5s|%5s|%7s|%7s|%8s|%6s|%10s|%6s|%7s|\n",$
  68. device, serial, temp, onHours, startStop, spinRetry, reAlloc, pending, offlineUnc, seekErrors, totalSeeks, hiFlyWr, cmdTimeout;$
  69. }'$
  70. ) >> ${logfile}$
  71. done$
  72. ($
  73. echo "+------+---------------+----+-----+-----+-----+-------+-------+--------+------+----------+------+-------+"$
  74. echo ""$
  75. echo ""$
  76. ) >> ${logfile}$
  77. $
  78. ###### for each drive ######$
  79. for drive in $drives$
  80. do$
  81. brand=`smartctl -i /dev/${drive} | grep "Model Family" | awk '{print $3, $4, $5}'`$
  82. serial=`smartctl -i /dev/${drive} | grep "Serial Number" | awk '{print $3}'`$
  83. ($
  84. echo ""$
  85. echo "########## SMART status report for ${drive} drive (${brand}: ${serial}) ##########"$
  86. smartctl -n never -H -A -l error /dev/${drive}$
  87. smartctl -n never -l selftest /dev/${drive} | grep "# 1 \|Num" | cut -c6-$
  88. echo ""$
  89. echo ""$
  90. ) >> ${logfile}$
  91. done$
  92. sed -i '' -e '/smartctl 6.3/d' ${logfile}$
  93. sed -i '' -e '/Copyright/d' ${logfile}$
  94. sed -i '' -e '/=== START OF READ/d' ${logfile}$
  95. sed -i '' -e '/SMART Attributes Data/d' ${logfile}$
  96. sed -i '' -e '/Vendor Specific SMART/d' ${logfile}$
  97. sed -i '' -e '/SMART Error Log Version/d' ${logfile}$
  98. echo "</pre>" >> ${logfile}$
  99. $
  100. ### Send report ###$
  101. sendmail -t < ${logfile}$
  102. rm ${logfile}$
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement