python 检测文件大小和修改时间
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 检测文件大小和修改时间相关的知识,希望对你有一定的参考价值。
#!/bin/env python #AUTHOR:karl #DATE:2017-10-31 #VERSION:V1.0 ###################### import time import os import paramiko import multiprocessing import datetime import sys private_key = paramiko.RSAKey.from_private_key_file('/home/appdeploy/.ssh/id_rsa') def TimeStampToTime(timestamp): timeStruct = time.localtime(timestamp) return time.strftime('%Y-%m-%d %H:%M:%S',timeStruct) def get_total(ager): # print "---------------",ager[0],ager[1],ager[2],ager[3],"----------" ssh=paramiko.SSHClient() try: ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect(hostname=ager[0],port=22,username='appdeploy',pkey=private_key,timeout=5) cmd="python /home/appdeploy/Filesize.py {age1} {age2} {age3}".format(age1=ager[2],age2=ager[1],age3=ager[3]) stdin,stdout,stderr = ssh.exec_command(cmd) for file_1 in stdout.readlines(): #print "-----\033[1;33m %s \033[0m : %s"%(ager[0],file_1) try: str_f="%s: %s"%(ager[0],file_1) file_w=open('fileresult','a') file_w.write(str_f) finally: file_w.close() except: result=ager[0]+','+'failed'+'\n' print result #/app/jetty/server/SCS_ATP_CORE_CNSZ17_JT_APP_CUSTOM_01/deploy/webapps ager={ "10.117.193.58":["1",{"ADMIN":["scc-web.war","scc-server.war"]},{"TRTS":["scc-server-portal.war","scc-web-portal.war"]},{"TRAPP":["scc-server-portal.war"]},"0"], "10.117.193.59":["2",{"ADMIN":["scc-web.war","scc-server.war"]},{"TRTS":["scc-server-portal.war","scc-web-portal.war"]},{"TRAPP":["scc-server-portal.war"]},"0"], "10.117.193.60":["3",{"ADMIN":["scc-web.war","scc-server.war"]},{"TRTS":["scc-server-portal.war","scc-web-portal.war"]},{"TRAPP":["scc-server-portal.war"]},"0"], "10.117.193.61":["4",{"ADMIN":["scc-web.war","scc-server.war"]},{"TRTS":["scc-server-portal.war","scc-web-portal.war"]},{"TRAPP":["scc-server-portal.war"]},"0"], "10.117.194.23":["1",{"CUSTOM":["atp-custom-sf.war"]},{"ADMIN":["scc-web.war","scc-server.war"]},{"TRTS":["scc-server-portal.war","scc-web-portal.war"]},{"TRAPP":["scc-server-portal.war"]}], "10.117.194.24":["2",{"CUSTOM":["atp-custom-sf.war"]},{"ADMIN":["scc-web.war","scc-server.war"]},{"TRTS":["scc-server-portal.war","scc-web-portal.war"]},{"TRAPP":["scc-server-portal.war"]}], "10.117.194.25":["3",{"CUSTOM":["atp-custom-sf.war"]},{"ADMIN":["scc-web.war","scc-server.war"]},{"TRTS":["scc-server-portal.war","scc-web-portal.war"]},{"TRAPP":["scc-server-portal.war"]}], "10.117.194.26":["4",{"CUSTOM":["atp-custom-sf.war"]},{"ADMIN":["scc-web.war","scc-server.war"]},{"TRTS":["scc-server-portal.war","scc-web-portal.war"]},{"TRAPP":["scc-server-portal.war"]}], } file_name="/opt/version_release/release_v1.0/release/bin/fileresult" file_cmd="echo > %s"%file_name if os.path.exists(file_name): os.system(file_cmd) ager_list=[] for k,v in ager.items(): ager_list.append(k) ager_list.append(v[0]) for i in range(1,5): if v[i] == '0': continue for pro, file_n in v[i].items(): ager_list.append(pro) if len(file_n) == 2: for j in file_n: ager_list.append(j) get_total(ager_list) ager_list.pop() else: ager_list.append(file_n[0]) get_total(ager_list) ager_list.pop() ager_list.pop() ager_list=[]
以上是关于python 检测文件大小和修改时间的主要内容,如果未能解决你的问题,请参考以下文章