Advertisement
Guest User

Untitled

a guest
Sep 19th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.61 KB | None | 0 0
  1. * The official, canonical repository is git.fabfile.org
  2. * The official Github mirror is GitHub/bitprophet/fabric
  3.  
  4. $ pip install fabric
  5. Downloading/unpacking fabric
  6. Downloading Fabric-1.4.2.tar.gz (182Kb): 182Kb downloaded
  7. Running setup.py egg_info for package fabric
  8. warning: no previously-included files matching '*' found under directory 'docs/_build'
  9. warning: no files found matching 'fabfile.py'
  10. Downloading/unpacking ssh>=1.7.14 (from fabric)
  11. Downloading ssh-1.7.14.tar.gz (794Kb): 794Kb downloaded
  12. Running setup.py egg_info for package ssh
  13. Downloading/unpacking pycrypto>=2.1,!=2.4 (from ssh>=1.7.14->fabric)
  14. Downloading pycrypto-2.6.tar.gz (443Kb): 443Kb downloaded
  15. Running setup.py egg_info for package pycrypto
  16. Installing collected packages: fabric, ssh, pycrypto
  17. Running setup.py install for fabric
  18. warning: no previously-included files matching '*' found under directory 'docs/_build'
  19. warning: no files found matching 'fabfile.py'
  20. Installing fab script to /home/hbrown/.virtualenvs/fabric-test/bin
  21. Running setup.py install for ssh
  22. Running setup.py install for pycrypto
  23. ...
  24. Successfully installed fabric ssh pycrypto
  25. Cleaning up...
  26.  
  27. ssh [host] [command]
  28.  
  29. process = subprocess.Popen("ssh example.com ls", shell=True,
  30. stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
  31. output,stderr = process.communicate()
  32. status = process.poll()
  33. print output
  34.  
  35. import socket
  36. import libssh2
  37.  
  38. sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  39. sock.connect(('exmaple.com', 22))
  40.  
  41. session = libssh2.Session()
  42. session.startup(sock)
  43. session.userauth_password('john', '******')
  44.  
  45. channel = session.channel()
  46. channel.execute('ls -l')
  47.  
  48. print channel.read(1024)
  49.  
  50. import spur
  51.  
  52. shell = spur.SshShell(hostname="localhost", username="bob", password="password1")
  53. result = shell.run(["echo", "-n", "hello"])
  54. print result.output # prints hello
  55.  
  56. result = shell.run(["echo", "-n", "hello"], stdout=sys.stdout)
  57.  
  58. import subprocess
  59. import sys
  60. HOST="IP"
  61. COMMAND="ifconfig"
  62.  
  63. def passwordless_ssh(HOST):
  64. ssh = subprocess.Popen(["ssh", "%s" % HOST, COMMAND],
  65. shell=False,
  66. stdout=subprocess.PIPE,
  67. stderr=subprocess.PIPE)
  68. result = ssh.stdout.readlines()
  69. if result == []:
  70. error = ssh.stderr.readlines()
  71. print >>sys.stderr, "ERROR: %s" % error
  72. return "error"
  73. else:
  74. return result
  75.  
  76. from ssh_decorate import ssh_connect
  77. ssh=ssh_connect('user','password','server')
  78.  
  79. #Run a python function
  80. @ssh
  81. def python_pwd():
  82. import os
  83. return os.getcwd()
  84.  
  85. print (python_pwd())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement