I want to make simple python script , which i can run on cron job. i just want to see if these services are currently running or stopped
Httpd
mysql
How should i check them with python.
Do i need to parse the output of netstat -tlnp
import subprocess
service = "apache2"
p = subprocess.Popen(["systemctl", "is-active", service], stdout=subprocess.PIPE)
(output, err) = p.communicate()
output = output.decode('utf-8')
print(output)
The Python program will check if the service is running. If it running, the output will be "active" otherwise the output will be "inactive".
Hope it helps!!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With