Advertisement
Masoko

copy file to remote hosts ssh

Dec 13th, 2017
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.90 KB | None | 0 0
  1. # Import Fabric's API module
  2. from fabric.api import *
  3.  
  4. hosts = [   {"host":"192.168.0.101", "password":"password", "user":"pi"},
  5.             {"host":"192.168.0.13", "password":"password", "user":"pi"},
  6.             {"host":"192.168.0.103", "password":"password", "user":"pi"},
  7.             {"host":"192.168.0.12", "password":"password", "user":"pi"},
  8.             {"host":"192.168.0.10", "password":"password", "user":"pi"},
  9.         ]
  10.  
  11. local_file = "/home/pi/scripts/cpu_mqtt.py"
  12. remote_file = "/home/pi/scripts/cpu_mqtt.py"
  13.  
  14. if __name__ == '__main__':
  15.     for host in hosts:
  16.         try:
  17.             # Set the username
  18.             env.user   = host['user']
  19.             env.host_string = host['host']
  20.             # Set the password [NOT RECOMMENDED]
  21.             env.password = host['password']
  22.             env.disable_known_hosts = True
  23.             with hide('everything'):
  24.                 put(local_file, remote_file)
  25.             print(env.host_string+" - Done")
  26.         except KeyboardInterrupt:
  27.             print("\n"+env.host_string+" - Failed")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement