I am trying to build this script to check if a file on a remote server contains a set suffix, IE .ok, .err, .log. I can’t figure out why I am getting the return that I am
"('\\\\THPNWSS5\\d$\\DA$Utils\\log\\networker', [], ['P3EWS.err']) nothing is equal“
I know there is something wrong with my try statement but I can’t see it.
chkbkpstats = csv.reader(file('c://temp//networkerservers1.csv'))
srvrs = []
for row in chkbkpstats:
srvrs.append({'Name' : row[0], 'Instance' : row[1]})
for srvr in srvrs:
srvrName = (srvr['Name'])
srvrInst = (srvr['Instance'])
w2k3chk = r'\\%s\d$\DA$Utils\log\networker' % srvrName
w2k8chk = r'\\%s\c$\ProgramData\folder\DA$Utils\log\networker' % srvrName
try:
c = wmi.WMI(srvr['Name'])
except:
print 'Error connecting to %s to check OS version' % srvrName
else:
osVer = c.Win32_OperatingSystem()[0].Caption
if '2003' in osVer:
for file in os.walk(w2k3chk):
print file
try:
if srvrInst == srvrInst + ".log":
print 'The Backup for %s on %s still running' % (srvrInst, srvrName)
if srvrInst == (srvrInst + ".ok"):
print 'Completed Successfully'
if srvrInst == (srvrInst + ".err"):
print 'Backup failed'
except:
print 'nothing is equal'
#print '%s is w2k3' % srvr['Name']
elif '2008' in osVer:
print '%s is w2k8' % srvr['Name']
While @लंड has pointed out the most pressing error in your current code, his suggested fix,
file == (srcInst + ".log")won’t work either. That’s because theos.walkfunction doesn’t just return filenames. It returns a generator of three-tuples, each consisting of a directory, a list of subdirectories (which will also be walked) and a list of files. You need an extra loop to go over the individual files.Something like this should work:
If you’re sure there should only ever be a single file in the folder you’re searching, you can simplify that a bit: