daily pastebin goal
11%
SHARE
TWEET

Untitled

a guest Sep 22nd, 2016 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {"path":"/home/Document/Python",
  2. "md5s":[{"filename":"",
  3.     "md5":"",
  4.     "timestamp":""},
  5.    {"filename":"",
  6.     "md5":"",
  7.     "timestamp":""},
  8.    {"filename":"",
  9.     "md5":"",
  10.     "timestamp":""}
  11. ]}
  12.    
  13. def filemd5():
  14.    try:
  15.     config = json.load(open(config_file))
  16.     #print(str(json.dumps(config, indent=4)))
  17.     for server in config['servers']:
  18.             ssh = SSHClient()
  19.             ssh.load_system_host_keys()
  20.  
  21.             ssh.connect(server['ip'], username=server['username'],
  22.                         password=server['password'])
  23.         #print(str(server))
  24.         print('Connecting to servers')
  25.         ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command('ls /tmp/')
  26.         error = str(ssh_stderr.read())
  27.         if len(error) ==0:
  28.             for files in config['servers']:
  29.                 filename = file_location + server['file']
  30.                 scp = SCPClient(ssh.get_transport())
  31.                 scp.get(filename)
  32.             if os.path.isfile(server['file']):
  33.                 updateJsonFile(filename)
  34.                 print(filename)
  35.             else:
  36.                 print('KO')
  37.  
  38. def updateJsonFile(filename):
  39.     jsonFile = open("md5.json", "r")
  40.     data = json.load(jsonFile)
  41.     jsonFile.close()
  42.  
  43.     tmp = data["md5s"]
  44.     data["filename"] = filename
  45.     jsonFile = open("md5.json", "w+")
  46.     jsonFile.seek(0)
  47.     jsonFile.write(json.dumps(data))
  48.     jsonFile.close()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top