Im trying to use a dictionary to check a given number of servers listed for a particular SQL backup success or fail. My problem so far is when I run this code:
for serverChk in srvrDict['Server']:
it returns the server name as single characters on each new line like:
S
E
R
V
E
R
So in my trial I see this "Error connecting to T to check OS version" where T is the fist character of the servername. I can't seem to put my finger on it and all the searching I've done has lead me to asking.
Thanks!
class checkstatus:
#def getServers(self):
chkbkpstats = csv.reader(file('c://temp//networkerservers.csv'))
for row in chkbkpstats:
srvrDict = {}
srvrDict['Server'] = row[0]
srvrDict['Instance'] = row[1]
print srvrDict
for serverChk in srvrDict['Server']:
try:
c = wmi.WMI(server)
for os in c.Win32_OperatingSystem():
osVer = os.caption
except:
print 'Error connecting to %s to check OS version' % serverChk
if '2003' in osVer:
print 'w2k3'
if '2008' in osVer:
print 'w2k8'
srvrDict['Server']is at the beginning of iteration? It looks like it's a single string and thus the iteration occurs over each character. If it's a delimited string of server names, you will need to split the list first.srvrDict['Server'], trytype(srvrDict['Server']), is it a dict or string?for serverChk in serverDict['Server']translates tofor serverChk in 'THP06ASU'. You should instead usefor instance,server in serverDict.iteritems(). Nowserveris the value you will want to print out. Or if you just want the values then you can usefor server in serverDict.values()