Advertisement
Guest User

Untitled

a guest
Aug 16th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. import sys
  2. import paramiko
  3. import getpass
  4.  
  5.  
  6. def ssh_command(ssh):
  7. command = 'cd plataforma ; source venv/bin/activate; python manage.py runserver 0:8000;'
  8. ssh.invoke_shell()
  9. stdin, stdout, stderr = ssh.exec_command(command)
  10. print(stdout.read())
  11.  
  12. def ssh_connect(host, user, key):
  13. try:
  14. ssh = paramiko.SSHClient()
  15. print('Calling paramiko')
  16. ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  17. ssh.connect(hostname=host, username=user, password=key)
  18.  
  19. ssh_command(ssh)
  20. except Exception as e:
  21. print('Connection Failed')
  22. print(e)
  23.  
  24. if __name__=='__main__':
  25. user = 'root'
  26. key = '123123'
  27. host = 'xxx.xxx.xxx.xxx'
  28. ssh_connect(host, user, key)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement