ha机器数量较多且系统不定,故做此脚本做自启动状态检测
import os
'''
linux系统信息获取,注意空格的删除,否则信息不匹配无法执行
执行前做好linux命令验证工作,确保脚本正常执行
'''
def fun():
system_version7 = "sudo cut -c 22 /etc/redhat-release"
system_version6 = "sudo cut -c 16 /etc/redhat-release"
sv7 = os.popen(system_version7, "r")
sv6 = os.popen(system_version6, "r")
version7 = sv7.readline().strip()
version6 = sv6.readline().strip()
if version7 == str(7):
os7_status = "sudo systemctl list-unit-files | grep haproxy | awk '{print $2}'"
sta7 = os.popen(os7_status, "r")
os7 = sta7.readline().strip()
if os7 == "enabled":
print("centos7 ha status ok")
elif version6 == str(6):
os6_status = "sudo chkconfig | grep haproxy | awk '{print $7}'"
sta6 = os.popen(os6_status, "r")
os6 = sta6.readline().strip()
if os6 == "5:on":
print("centos6 ha status ok ")
else:
print("message error")
if __name__ == '__main__':
fun()