Advertisement
posean

Untitled

Jun 29th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.75 KB | None | 0 0
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3.  
  4. import paramiko
  5. servers = {}
  6. config = open('/home/polichnoy/param.test').read().split('\n')
  7. for i in config:
  8.     if len(i) > 0:
  9.         i = i.split()
  10.         servers[i[0]] = i[1]
  11.  
  12.  
  13. def ssh_conn(host, user, secret, port, value):
  14.     client = paramiko.SSHClient()
  15.     client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  16.     client.connect(hostname=host, username=user, password=secret, port=port)
  17.     stdin, stdout, stderr = client.exec_command("echo '%s' > /home/polichnoy/hostname" % (value))
  18.     stdin, stdout, stderr = client.exec_command("echo '%s' > /home/polichnoy/hostname1" % (value))
  19.     data = stdout.read() + stderr.read()
  20.     client.close()
  21.     print data
  22.  
  23. for i in servers:
  24.     ssh_conn(i, 'polichnoy', '111111', 22, servers[i])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement