Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # These are the two directories I want to work with.
- # ip_path is the directory that store the old IP
- # new_ip_path is the the directory that has the update IP
- ip_path = '\Users\qnguyen\backup_conf'
- new_ip_path = 'Users\qnguyen\new_ips'
- import os, re
- # my_reg take all the characters in the string up to .ip
- my_reg = re.compile('(\w+)\.ip')
- # This command should give me access to the root, directories and files in new_ip_path
- for root,directories,files in os.walk(new_ip_path):
- # So I get all the name in that directory and put in in the list host_files
- host_files = [("%s.pl" % my_reg.match(h).group(1)) for h in files]
- # for each name in host file, I want to open that file in the other path and replace the old IP with the new
- for f in host_files:
- # open the text file and read in the the line.
- oldIPfile = open(os.path.join(new_ip_path,f)
- my_newIP = oldIPfile.readline()
- # I don't get why there a syntax error. I'm just storing the line that I read in
- # Then I should open the directory that store the old IP and replace it with the new one
- my_string = re.comple('/^(\d+.?){4}$/')
- # for each line I want to find the old IP, which is in the line that contains ClientNameAlias
- # and replaces it with the new IP using sub()
- for line in open(os.path.join(ip_path,f))
- if "ClientNameAlias" in line:
- my_string.sub(my_newIP, line)
- print("%s 's old IP was replace." % f)
- else:
- print("%s could not be found" % f)
Add Comment
Please, Sign In to add comment