[dba-Tech] S.M.A.R.T. monitoring

John R Bartow jbartow at winhaven.net
Fri Nov 21 12:24:03 CST 2014


Hi Gustav,
http://www.smartmontools.org may be what you're looking for.
You should be able to find smartctl here, which is scriptable.

Here's a script I use with my RMS but it should run once manually:
'Begin script

'Original script by Ivan Kelleher @ Etelligence, Mar 2013
'an argument should to be passed for the script to run
'to identify attached devices and parameters run the command: smartctl
--scan
'Pass the relevent argument to the script, e.g. C: or /dev/sda
'Pass Disabled to bypass the check, pass 2nd argument as optional reason,
e.g. Disabled Incompatible
'
'Changes from previous
'1. Added "-t force" to test command line. Is -X depreciated?
'
'Notes:
'1. Only ATA devices are supported.

'Parameters
strFileURL = "http://www.winhaven.net/cloud/utilities/smartctl.exe"
exefile = "smartctl.exe"
extraparam = " "

'Download
	'Set Objects
	Set objFSO = CreateObject("Scripting.FileSystemObject")
	 
	'Does application already Exist?
	If not objFSO.Fileexists(exefile) Then 
	 
	'Download application
	Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP")
	 
	objXMLHTTP.open "GET", strFileURL, false
	objXMLHTTP.send()
	 
	If objXMLHTTP.Status = 200 Then
	 
	Set objADOStream = CreateObject("ADODB.Stream")
	objADOStream.Open
	objADOStream.Type = 1 'adTypeBinary
	 
	objADOStream.Write objXMLHTTP.ResponseBody
	objADOStream.Position = 0
	 
	Set objFSO = Createobject("Scripting.FileSystemObject")
	 
	If objFSO.Fileexists(exefile) Then objFSO.DeleteFile exefile
	Set objFSO = Nothing
	 
	objADOStream.SaveToFile exefile
	objADOStream.Close
	Set objADOStream = Nothing
	 
	End if
	 
	End if

'Check for empty argument
if WScript.Arguments.Count = 0 then
	WScript.Echo "ERROR No parameters given. Output from device scan:"
		
	Set WshShell = WScript.CreateObject("WScript.Shell")
	Set oExec = WshShell.Exec(exefile & " --scan-open")
	
	'We wait for the end of process
	Do While oExec.Status = 0
		WScript.Sleep 100
	Loop
	
	'We scan and display the command output flow
	Do While oExec.StdOut.AtEndOfStream <> True
		Wscript.Echo oExec.StdOut.ReadLine
	Loop
	
	WScript.Quit 2
else
	inputarg = Wscript.Arguments.Item(0)
end if

If Wscript.Arguments.Item(0) = "Disabled" then
	if not Wscript.Arguments.Item(1) = ""  then
		WScript.Echo "Disabled: " & Wscript.Arguments.Item(1)
	else
		WScript.Echo "Disabled"
	end if
	WScript.Quit	
End if
	
'Stop any test running
	Set WshShell = WScript.CreateObject("WScript.Shell")
	Set oExec = WshShell.Exec(exefile & " -X " & extraparam & inputarg)

	'We wait for the end of process
	Do While oExec.Status = 0
		WScript.Sleep 100
	Loop

	'Try alternative
	If not oExec.ExitCode = 0 then 
		extraparam = " -d sat,16 "
		Set WshShell = WScript.CreateObject("WScript.Shell")
		Set oExec = WshShell.Exec(exefile & " -X " & extraparam &
inputarg)
	
		'We wait for the end of process
		Do While oExec.Status = 0
			WScript.Sleep 100
		Loop

		If not oExec.ExitCode = 0 then 
			WScript.Echo exefile & " finished with errors. Exit
code 1:" & oExec.ExitCode
			WScript.Quit oExec.ExitCode
		End If
	End If


'Turn on SMART and start short self-test
	Set WshShell = WScript.CreateObject("WScript.Shell")
	Set oExec = WshShell.Exec(exefile & " -s on -t short -t force " &
extraparam & inputarg)

	'We wait for the end of process
	Do While oExec.Status = 0
		WScript.Sleep 100
	Loop

	'Try alternative
	If not oExec.ExitCode = 0 then 
		extraparam = " -d sat,16 "
		Set WshShell = WScript.CreateObject("WScript.Shell")
		Set oExec = WshShell.Exec(exefile & " -s on -t short -t
force " & extraparam & inputarg)
	
		'We wait for the end of process
		Do While oExec.Status = 0
			WScript.Sleep 100
		Loop

		If not oExec.ExitCode = 0 then 
			WScript.Echo exefile & " finished with errors. Exit
code 2:" & oExec.ExitCode
			WScript.Quit oExec.ExitCode
		End If
	End If

'Test for failing attributes
	Set WshShell = WScript.CreateObject("WScript.Shell")
	Set oExec = WshShell.Exec(exefile & " -q errorsonly -A -f brief -l
selftest " & extraparam & inputarg)

	'We wait for the end of process
	Do While oExec.Status = 0
		WScript.Sleep 100
	Loop
	
	AttributeResult = 0
	
	'We scan and display the command output flow
	Do While oExec.StdOut.AtEndOfStream <> True
		strTemp = oExec.StdOut.ReadLine
		If InStr(strtemp, " ") > 0 Then
			AttributeResult = AttributeResult + 1
			If not InStr(strtemp, "ID#") > 0 Then
				Wscript.Echo strtemp
			End If
			'Ignore Past errors in Airflow_Temperature_Cel
			If InStr(strtemp, "Airflow_Temperature_Cel") > 0
Then
				If InStr(strtemp, "Past") > 0 Then
					AttributeResult = AttributeResult -
2
				End If
			End If
		End If
	Loop

	Wscript.Echo strtemp
	
	If not oExec.ExitCode = 0 then 
		WScript.Echo exefile & " finished with errors. Exit code 3:"
& oExec.ExitCode
		WScript.Quit oExec.ExitCode
	End If
	
'Test SMART
	Set WshShell = WScript.CreateObject("WScript.Shell")
	commandline = exefile & " -H " & extraparam & inputarg
	Set oExec = WshShell.Exec(commandline)	
	
	'We wait for the end of process
	Do While oExec.Status = 0
		WScript.Sleep 100
	Loop
		
	'We scan and display the command output flow
	Do
		strTemp = oExec.StdOut.ReadLine

		If InStr(strtemp, "PASSED") > 0 Then
			Wscript.Echo "SMART test on device " & inputarg & "
PASSED"
			WScript.Quit AttributeResult
		ElseIf InStr(strtemp, "FAILED") > 0 Then
			Wscript.Echo "SMART test on device " & inputarg & "
FAILED"
			WScript.Quit 1
		End If
		
	Loop While Not oExec.StdOut.AtEndOfStream 

	If not oExec.ExitCode = 0 then 
		WScript.Echo exefile & " finished with errors. Exit code 4:"
& oExec.ExitCode
		WScript.Quit oExec.ExitCode
	End If

WScript.Quit 1

'End of Script

Regards,
John B


-----Original Message-----
From: dba-tech-bounces at databaseadvisors.com
[mailto:dba-tech-bounces at databaseadvisors.com] On Behalf Of Gustav Brock
Sent: Tuesday, November 18, 2014 4:28 AM
To: Discussion of Hardware and Software issues
Subject: [dba-Tech] S.M.A.R.T. monitoring

Hi all

I'm looking for a utility that can run as a Windows service and monitor
harddisks' S.M.A.R.T. log.
Any recommendations?

/gustav
_______________________________________________
dba-Tech mailing list
dba-Tech at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/dba-tech
Website: http://www.databaseadvisors.com




More information about the dba-Tech mailing list