I am writing a wrapper for smartctl in python 2.7.3 ...
I have time trying to wrap my head around how to analyze output from a program smartctlon Linux (specific Ubuntu x64)
I run smartctl -l selftest /dev/sdxthrough a subprocess and grab the output to a variable
This variable is split into a list, then I remove the useless header data and empty lines from the output.
Now I am left with a list of strings, which is great!
The data is sorted by tables, and I want to analyze them in a dict () file full of lists (I think this is the right way to represent tabular data in Python from reading documents)
Here is an example of data:
Num Test_Description Status Remaining LifeTime(hours) LBA_of_first_error
I see some problems trying to parse this, and I'm open to solutions, but I can also just do it all wrong :-):
Self-test routine in progress RemainingNum 9 #
, , - .
, !
, - :
import subprocess
def cleanOutput(data):
cleanedOutput = []
del data[0:3]
for item in data:
if item == '':
pass
else:
cleanedOutput.append(item)
return cleanedOutput
def resultsOutput(data):
headerLines = []
resultsLines = []
resultsTable = {}
for line in data:
if "START OF READ" in line or "log structure revision" in line:
headerLines.append(line)
else:
resultsLines.append(line)
nameLine = resultsLines[0].split()
print nameLine
def getStatus(sdxPath):
try:
output = subprocess.check_output(["smartctl", "-l", "selftest", sdxPath])
except subprocess.CalledProcessError:
print ("smartctl command failed...")
except Exception as e:
print (e)
splitOutput = output.split('\n')
cleanedOutput = cleanOutput(splitOutput)
resultsOutput(cleanedOutput)
getStatus("/dev/sdb")