Python detects file size and modification time

Source: Internet
Author: User

#!/bin/env python#author:karl#date:2017-10-31#version:v1.0##################### #import  timeimport  osimport paramikoimport multiprocessingimport datetimeimport sysprivate_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/webappsager={        "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_nameif 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 ()             &Nbsp;ager_list.pop ()     ager_list=[]


Python detects file size and modification time

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.