Koozali.org: home of the SME Server

a script to place the results of SMART info from 2 SATA drives in raid 1 mode

Offline purvis

  • ****
  • 567
  • +0/-0
This script will collect SMART info from up to 2 sata drives place in a sme 8 server.
Usually the drives are in RAID 1 mode.

You can get the information from a webpage  "http://yourserver/serverstatus/smartrpt.txt"
or with the php code place found on the bottom

bash script named smartrpt
place the script file some where and make it executable
edit /etc/rc.local file and place the bash script file name in the last line in the file with a space and an ampersand sign behind it to make the script load up at boot.

You can change  the seconds to wait from 51 to anything number higher, with 60 seconds being added each time to increase your report time period, but i like 1 minute between reports, because I stay busy.

This routine is set to build a report at the top of every minute within the the first 19 seconds or 20 if you want to count 00 to 19
Code: [Select]

#  variables start -----------------------------------------------



#  variables end -------------------------------------------------

function makesmartreport {
   if [ ! -d "$sfilelocation" ];then
      mkdir -p "$sfilelocation"
      chmod 755 "$sfilelocation"
   rm -rf "$sfullreportnametmp"
   echo "This report is created at the top of every minute." >  "$sfullreportnametmp"
   echo "Computer $HOSTNAME" >>  "$sfullreportnametmp"
   date >> "$sfullreportnametmp"
   echo ""                >> "$sfullreportnametmp"
   echo ""                >> "$sfullreportnametmp"
   echo "                  =HARD DRIVE 1=" >> "$sfullreportnametmp"
   echo "============================================================================" >> "$sfullreportnametmp"
   echo "Information for drive started"  >> "$sfullreportnametmp"
   smartctl -a /dev/sda   >> "$sfullreportnametmp"
   echo "Information for drive ended"    >> "$sfullreportnametmp"
   echo ""                >> "$sfullreportnametmp"
   echo "                  =HARD DRIVE 2=" >> "$sfullreportnametmp"
   echo "============================================================================" >> "$sfullreportnametmp"
   echo "Information for drive started"  >> "$sfullreportnametmp"
   smartctl -a /dev/sdb   >> "$sfullreportnametmp"
   echo "Information for drive ended"    >> "$sfullreportnametmp"
   echo ""                >> "$sfullreportnametmp"
   echo "End of the report"   >> "$sfullreportnametmp"
   rm -rf "$sfullreportname"
   mv "$sfullreportnametmp"  "$sfullreportname"


while [ -1 ];do
second=$(date +"%S")
tenthsecond=$(echo ${second:0:1})
if [ "$tenthsecond" == "0" ] || [ "$tenthsecond" == "1" ] ;then
   sleep 51
   sleep 3

exit 0

The php code which reads the smartrpt.txt report file and places the text in a web page.
This is nice if you want to change the fonts in the php web page for better viewing on your preferred equipment.
To use the php webpage, place the php code in the directory of "/home/e-smith/files/ibays/Primary/html/serverstatus"
The directory will be created for you if you run the above script first.
I named the file smartrpt.php

to run the webpage "http://yourserver/serverstatus/smartrpt.php"

Code: [Select]
<!--DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"-->

<head><title>SMART report on drives</title></head>
print "<pre>";
'<font size="3">';
"SMART report on drives\n";
$filecontents='The report is not available now. Retry';


For what it is worth, using a browser to directory view the smartrpt.txt file should be much faster than using the php to display the file.
« Last Edit: June 07, 2013, 04:25:01 AM by purvis »