Skip to content

Instantly share code, notes, and snippets.

@mohclips
Created February 11, 2019 19:35
Show Gist options
  • Save mohclips/acbb853fa4bc1641a9c18fcbf843f614 to your computer and use it in GitHub Desktop.
Save mohclips/acbb853fa4bc1641a9c18fcbf843f614 to your computer and use it in GitHub Desktop.
Example of subprocess.checkoutput and rndc
def reload_zone(origin):
for action in ['status','freeze', 'reload', 'thaw', 'status']:
print('doing... rndc', action, origin)
cmd = ['/usr/sbin/rndc', action, origin]
try:
Out = subprocess.check_output(cmd,stderr=sys.stdout.buffer,universal_newlines=True)
print("{}".format(Out))
except subprocess.CalledProcessError as rndcexc:
print("Error code {} {}".format(rndcexc.returncode, rndcexc.output))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment