#!/usr/bin/python # 2010302 jan@panoch.com # scan all connected STEC drives # with sdmcmd utility import re import subprocess from pprint import pprint def SysCmdLines (cmd): """Do system command and return lines""" p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) return p.stdout.readlines() # # main # hosts = [] for line in SysCmdLines("./sdmcmd64 ScanLocal"): line = line.rstrip() if "devices[" in line: # print "line=[%s]" % line m = re.search(r" = (\S+)$", line) if m and not "other:" in m.group(1): host = m.group(1) hosts.append(host) # print "found host=[%s]" % (host) # pprint(hosts) serials = {} for host in hosts: # print "host="+host for line in SysCmdLines("./sdmcmd64 GetInfo target="+host): line = line.rstrip() if " = " in line: # print "line=[%s]" % line m = re.search(r"serialNumber = '(\S+)", line) if m: sn = m.group(1) serials[host] = sn # collect info infofname = sn+".txt" diagfname = sn+".bin" info = '' info += "".join(SysCmdLines("./sdmcmd64 GetInfo target="+host)) info += "".join(SysCmdLines("./sdmcmd64 GetState target="+host)) info += "".join(SysCmdLines("./sdmcmd64 GetStatistics level=SinceMade target="+host)) info += "".join(SysCmdLines("echo 'diagnosticType=Type1';./sdmcmd64 RunDiagnostic diagnosticType=Type1 target="+host)) info += "".join(SysCmdLines("echo 'diagnosticType=Type2';./sdmcmd64 RunDiagnostic diagnosticType=Type2 target="+host)) info += "".join(SysCmdLines("echo 'diagnosticType=Type3';./sdmcmd64 RunDiagnostic diagnosticType=Type3 target="+host)) info += "".join(SysCmdLines("echo 'diagnosticType=Type4';./sdmcmd64 RunDiagnostic diagnosticType=Type4 target="+host)) info += "".join(SysCmdLines("echo 'diagnosticType=Type5';./sdmcmd64 RunDiagnostic diagnosticType=Type5 target="+host)) info += "".join(SysCmdLines("./sdmcmd64 TestUnit target="+host)) info += "".join(SysCmdLines("./sdmcmd64 CaptureFieldData target="+host+" filename="+diagfname)) # write info to file with open(infofname,"w") as text_file: text_file.write(info) print "found host=[%s] serial=[%s] - info_file=[%s] diag_file=[%s]" % (host,sn,infofname,diagfname)