Guest User

Untitled

a guest
Jun 17th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. #!/usr/bin/python
  2. #-*- coding:Utf-8 -*-
  3. import os
  4. import time
  5. import sys
  6. import subprocess
  7.  
  8.  
  9.  
  10. source = []
  11. print sys.argv
  12. for i in range(len(sys.argv)):
  13. source.append(sys.argv[i])
  14.  
  15. source.remove(source[0])
  16. source.remove(source[0])
  17.  
  18. print source
  19. print sys.argv[1]
  20.  
  21. target_dir = sys.argv[1]
  22. today = target_dir + os.sep + time.strftime('%Y%m%d')
  23. now = time.strftime('%H%M%S')
  24.  
  25. if sys.argv[1][0] == "/" :
  26. print sys.argv[1] + "local"
  27. if not os.path.exists(today):
  28. os.mkdir(today) # cree le repertoire
  29.  
  30. target = today + os.sep + now + '.zip'
  31.  
  32. zip_command = "zip -qr {0} {1}".format(target, ' '.join(source))
  33.  
  34. if os.system(zip_command) == 0:
  35. print 'Sauvegarde reussie vers', target
  36.  
  37. else:
  38. print 'Echec de la sauvegarde'
  39.  
  40.  
  41. else :
  42. home = os.path.expanduser('~')
  43. print home
  44. print sys.argv[1] + "network"
  45.  
  46. target_dir = "%s/Bureau" % home
  47. print target_dir
  48. today = target_dir + os.sep + time.strftime('%Y%m%d')
  49. now = time.strftime('%H%M%S')
  50. if not os.path.exists(today):
  51. os.mkdir(today) # cree le repertoire
  52. target = today + os.sep + now + '.zip'
  53. print target
  54. zip_command = "zip -qr {0} {1}".format(target, ' '.join(source))
  55. if os.system(zip_command) == 0:
  56. print 'Sauvegarde local reussie vers', target
  57.  
  58. else:
  59. print 'Echec de la sauvegarde local'
  60.  
  61.  
  62. target_dir = sys.argv[1]
  63.  
  64. remote_path = "/home/hatim/Bureau/"
  65. print remote_path
  66.  
  67. password = "444444"
  68.  
  69.  
  70. print today
  71.  
  72. script = "/home/ismail/Bureau/SaveProg/scpmotdepasse1.sh"
  73. params = [script, today, remote_path, target_dir, password]
  74. cmd = " ".join(params)
  75. print(cmd)
  76. os.system(cmd)
Add Comment
Please, Sign In to add comment