#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ #需求: #动态捕获指定服务器最新发布接种应用系统路径,重启路径下tocmat,验证tomcat 是否重启成功--目前依据判断 #(系统时间 pk 当前路径下tomcat logs 路径下catalina.out时间戳)或是获取系统盘符下最新logs\vaccinate 时间戳,定位最新发布路径 # #实现思路: #搜索指定系统盘符列表,根据规则拼凑接种应用系统路径,判断路径是否存在,存在继续判断应用日志文件目录修改时间戳, #不存在直接下一个盘符路径,直到找到当前指定最新发布使用的应用接种系统盘符路径,下一步尝试重启检索到的接种 #发布路径,最后尝试判断重启是否成功。 #需求拆分 #1、获取当前系统盘符列表 #2、获取最新发布接种盘符路径 #3、尝试重启最新发布接种路径下tomcat #4、验证重启是否成功 #查找出系统接种系统,对比时间戳,获得当前正在使用的发布路径 #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ import time import os import sys import string #获取系统盘符列表 def get_disklist(): disk_list = [] for c in string.ascii_uppercase: disk = c + ':\\' if os.path.isdir(disk): disk_list.append(disk) return disk_list #print("xx") #for i01,i02,i03 in os.walk(r'c:\\'): #for i01,i02,i03 in os.walk(r'd:\\'): #print(i01) #time.sleep(2) #if 'appServer' in i01: # print(i03) #if r'appServer\tomcat_vacc' in i01: #if r'tomcat_vacc\logs\vaccinate' in i01: #if r'logs\vaccinate' in i01: # print(i01) for disk in get_disklist(): #print(disk) #print(os.walk(disk)) #print('r' + disk + r'\\') for i01,i02,i03 in os.walk(disk): if r'logs\vaccinate' in i01 and 'upload' not in i01: print(i01) print(time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(os.stat(i01).st_mtime))) #print(time.localtime(os.stat(i01).st_mtime)) #print(time.asctime(time.localtime(os.path.getmtime(i01)))) dt = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(os.stat(i01).st_mtime)) timeArray = time.strptime(dt, "%Y-%m-%d %H:%M:%S") #print(timeArray) timestamp = time.mktime(timeArray) print(timestamp) if __name__ == '__main__': #print(get_disklist()) #for i in get_disklist(): # print(i) #大小写字母 #for ix in string.ascii_lowercase: #for ix in string.ascii_uppercase: # dis = ix + ":" # print(ix) # print(dis) #print(dir(string)) pass