Dec 09 2016

Check Service Status With Python on OEL 7 / Centos 7

Category: Linux & Unix,PythonFatih Acar @ 21:42

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()

Download

Execute Script

If service is running
root@test ~]# python check_service_status.py
Running

If service is down
root@test ~]# python check_service_status.py
Stopped

11,686 total views, 10 views today

Tags: Linux Administration, Python, System Administration

facebook comments:

One Response to “Check Service Status With Python on OEL 7 / Centos 7”

  1. python programing – 一站 says:

    […] Check Service Status With Python on OEL 7 / Centos 7 […]

Leave a Reply

Time limit is exhausted. Please reload CAPTCHA.