我就废话不多说了,直接看代码吧!
成都创新互联从2013年开始,是专业互联网技术服务公司,拥有项目成都做网站、成都网站设计网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元沂水做网站,已为上家服务,为沂水各地企业和个人服务,联系电话:028-86922220#!/usr/bin/env python3 # -*- coding: utf-8 -*- # 输出 mysql2redis 命令 # __author__ = caozhi # create_time 2018-11-12,update_time 2019-12-12 # version = 2.0 import os import re import sys import time import fcntl import subprocess import requests ip = "8.8.8.8" urlnginxA = "http://8.8.8.8:81/version" urlnginxB = "http://8.8.8.8:82/version" defaultversion = {"module":"nginx","ver":"v0.0.0"} def ApplicationInstance(): global pidfile pidfile = open(os.path.realpath(__file__), "r") try: fcntl.flock(pidfile, fcntl.LOCK_EX | fcntl.LOCK_NB) #创建一个排他锁,并且所被锁住其他进程不会阻塞 #print('continue...') except: print('error', 'The script was executed many times...') sys.exit(1) def getversion(url): try: nginx_response = requests.get(url, timeout=3) if nginx_response.status_code == 200: data=nginx_response.json() else: print('\033[31m 接口响应非200,请重新确认执行,默认忽略本次接口的相应 %s http_code:%s\033[0m'%(url, nginx_response.status_code)) data = defaultversion except Exception as e: print('\033[31m 接口建联失败,请重新确认,默认忽略本次接口的相应 %s \033[0m'%url) print(e) data = defaultversion finally: return data def nginx_version(data): version = data['ver'].split('v')[1] return version if __name__ == '__main__': ApplicationInstance() nginxA_data = getversion(urlnginxA) nginxB_data = getversion(urllnginxB) print('\033[33m nginxA_version \033[0m %s'%nginxA_data) print('\033[33m nginxB_version \033[0m %s'%nginxB_data) versionA = nginx_version(nginxA_data) versionB = nginx_version(nginxB_data) d0=re.split('\.', versionA) d2=re.split('\.', versionB) d0=[int(d0[i]) for i in range(len(d0))] d2=[int(d2[i]) for i in range(len(d2))] print() if(d0>d2): print('\033[35m nginxA \033[0m这个版本大 v{}'.format(versionA)) print('\033[36m********* ↓ 这是要执行的mysql2redis的命令 请手动执行↓ ********* \033[0m') print('ssh {} "curl -v http://127.0.0.1:81/mysql2redis"'.format(ip)) if(d0
分享题目:python3自动打印出最新版本执行的mysql2redis实例-创新互联
分享路径:http://cdweb.net/article/cdsieh.html