#!/usr/bin/python import socket,os,time data={ 8080:"tomcat9", 18080:"tomcat_hjgdmj", 14080:"tomcat_hjpxmj" } for i in data: t=time.localtime() sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) result = sock.connect_ex(('127.0.0.1',i)) if 0 != result: print('%r restart: %s' %(time.asctime(t),data[i])) tomcat_name=data[i] os.environ['tomcat_name']=str(tomcat_name) os.system("/bin/bash /data/${tomcat_name}/bin/startup.sh") else: print('%r %s status is ok' %(time.asctime(t),data[i]))