Nov-08-2018, 02:47 PM
(This post was last modified: Nov-08-2018, 02:48 PM by wardancer84.)
update: got the first step working, i can now add stanza lines if they dont exist, and avoid duplicates. it's something
#!/usr/bin/env python import re config_file="stanza_test" stanza_name="smittyjohn" with open(config_file, 'r+') as fh: text = fh.read() if re.search('(?m)^' + stanza_name + ':', text): print('stanza found.') else: print('stanza not found.') fh.seek(0) fh.write( text + "\n" + stanza_name + ":\n" )
root@lpgaixmgmtlx01:/root>./add_stanza.py stanza not found. root@lpgaixmgmtlx01:/root>./add_stanza.py stanza found. root@lpgaixmgmtlx01:/root>./add_stanza.py stanza found. root@lpgaixmgmtlx01:/root>cat stanza_test smittyjohn: shittyjohn: