Skip to content

Instantly share code, notes, and snippets.

@phanthaihuan
Created May 13, 2020 15:32
Show Gist options
  • Save phanthaihuan/286d96e19d142de7651bac5263b1700a to your computer and use it in GitHub Desktop.
Save phanthaihuan/286d96e19d142de7651bac5263b1700a to your computer and use it in GitHub Desktop.
Get the output of Linux command
#!/usr/bin/env python
import os
def isActive(daemon):
command = "systemctl is-active " + daemon + " > tmp"
os.system(command)
with open('tmp') as tmp:
tmp = tmp.read()
if "active" in tmp:
os.remove('tmp')
return 1
return 0
sshd = "sshd"
print(isActive(sshd))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment