Created
May 13, 2020 15:32
-
-
Save phanthaihuan/286d96e19d142de7651bac5263b1700a to your computer and use it in GitHub Desktop.
Get the output of Linux command
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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