Skip to content

Commit 4c65ab7

Browse files
committed
add check for add cmd to rc.local
1 parent 2296167 commit 4c65ab7

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

add_ip.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,15 @@ def valid_ip(ipstr):
163163
except (AttributeError, TypeError):
164164
return False # `ip` isn't even a string
165165

166+
def lines_that_equal(filename, line_to_match):
167+
try:
168+
fp = open(filename,"r")
169+
for line in fp:
170+
if line.strip() == line_to_match.strip():
171+
return 1
172+
return 0
173+
finally:
174+
fp.close()
166175

167176

168177
# ################# main route ######################
@@ -291,13 +300,15 @@ def valid_ip(ipstr):
291300
if ret != 0:
292301
LOG.error("run cmd %s failed: %s.", ifcmd, errout)
293302
else:
294-
rcfile.write(ifcmd)
303+
if lines_that_equal(rclocal, ifcmd) == 0:
304+
rcfile.write(ifcmd)
295305

296306
ret, output, errout = exec_cmd_with_stderr(routecmd)
297307
if ret != 0:
298308
LOG.error("run cmd %s failed: %s.", routecmd, errout)
299309
else:
300-
rcfile.write(routecmd)
310+
if lines_that_equal(rclocal, routecmd) == 0:
311+
rcfile.write(routecmd)
301312

302313
endstr = "# End %s ip.\n" % (options.suffix)
303314
if options.debug:

0 commit comments

Comments
 (0)