I write a python code to check mysql service open or close. It is simple and you can change service_name parameter in the code to check another services. You can download from here check_service_status.py Below code maybe can not run because of python language format is tab structure. You can use with download original code check_service_status.py
Check MySQL Service Status
#-*- coding: utf-8 -*- import os import commands service_name = "mysql" def check_service_status(service_name): status = os.system('systemctl status '+service_name+ ' > /dev/null') return status def main(): if (check_service_status(service_name) == 0): print "Running" else: print "Stopped" main()
Execute Script
If service is running
root@test ~]# python check_service_status.py
RunningIf service is down
root@test ~]# python check_service_status.py
Stopped
1 thought on “Check Service Status With Python on OEL 7 / Centos 7”