Feb-24-2019, 08:28 AM
(Feb-24-2019, 08:17 AM)buran Wrote:(Feb-24-2019, 07:58 AM)searching1 Wrote: After running this from my original file which Im working, It's not writing any data on the CSV, maybe u have encountered/ any idea with this?I am not sure I understand this
There no data after running the script. no trace or anything will running. It's just no data can be seen once you open the csv file.
Posting my config. maybe you can see something unusual. Thanks
import re, base64, os, sys, subprocess, csv, itertools with open('list.txt') as csvfile: rilist = csv.reader(csvfile, delimiter=',') #Put the data from excel here rtrlist = [] intlist = [] ilist =[] dlist = [] blist = [] #Action - Put the data from excel to variable[list] for col in rilist: rtr = col[0] intf = col[1] rtrlist.append(rtr) intlist.append(intf) ## csvfile.close() ## print(rtrlist,"\n",intlist) #Change Directory os.chdir("/rs/configs") print("pwd=%s" % os.getcwd()) ## START OF THE LOOP ## for a,b in zip(rtrlist, intlist): srtr = a.strip() sint = b.strip() subint = re.sub("\d+\/*", "", sint) print ("Processing.... ",srtr,sint) proc = subprocess.Popen(("grep", "-A11", "interface %s"%sint, srtr), stdout = subprocess.PIPE) lbl = proc.communicate()[0] teststr = lbl.decode() print (teststr) #SEARCH INTERFACES ipat = re.findall(r"(?P<intrfname>%s+\d+\/.*)" %subint, teststr) ilist.append(ipat) print ("List of Interface: \n",ipat) #SEARCH INTERFACE DESCRIPTION dpat = re.findall("(?<=description\s)([A-Za-z0-9]+\;.*)", teststr) ## dpat = ','.join(ddpat) dlist.append(dpat) print ("\nDescription: ",dpat) #GET BUNDLE ID / CHANNEL GROUP bbpat = re.findall("(?<=bundle id\s)+\d+", teststr) bpat = ','.join(bbpat) blist.append(bpat) print ("\nBundled: ",bpat) print ("\nRTR List: ",rtrlist) print ("\nINT List: ",ilist) print ("\nDESC List: ",dlist) print ("\nBUN List: ",blist) rtrlist = [[ele] for ele in rtrlist] dlist = [[ele] for ele in dlist] ## EXPORT AS CSV with open('intlist.csv', 'w', newline='') as updatecsv: write = csv.writer(updatecsv, delimiter=',',lineterminator='\n') for cols in zip(rtrlist,ilist,dlist): rows = itertools.zip_longest(*cols, fillvalue='') write.writerows(rows) updatecsv.close() print ("\n Done...csv file has been updated")