Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- * The official, canonical repository is git.fabfile.org
- * The official Github mirror is GitHub/bitprophet/fabric
- $ pip install fabric
- Downloading/unpacking fabric
- Downloading Fabric-1.4.2.tar.gz (182Kb): 182Kb downloaded
- Running setup.py egg_info for package fabric
- warning: no previously-included files matching '*' found under directory 'docs/_build'
- warning: no files found matching 'fabfile.py'
- Downloading/unpacking ssh>=1.7.14 (from fabric)
- Downloading ssh-1.7.14.tar.gz (794Kb): 794Kb downloaded
- Running setup.py egg_info for package ssh
- Downloading/unpacking pycrypto>=2.1,!=2.4 (from ssh>=1.7.14->fabric)
- Downloading pycrypto-2.6.tar.gz (443Kb): 443Kb downloaded
- Running setup.py egg_info for package pycrypto
- Installing collected packages: fabric, ssh, pycrypto
- Running setup.py install for fabric
- warning: no previously-included files matching '*' found under directory 'docs/_build'
- warning: no files found matching 'fabfile.py'
- Installing fab script to /home/hbrown/.virtualenvs/fabric-test/bin
- Running setup.py install for ssh
- Running setup.py install for pycrypto
- ...
- Successfully installed fabric ssh pycrypto
- Cleaning up...
- ssh [host] [command]
- process = subprocess.Popen("ssh example.com ls", shell=True,
- stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
- output,stderr = process.communicate()
- status = process.poll()
- print output
- import socket
- import libssh2
- sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- sock.connect(('exmaple.com', 22))
- session = libssh2.Session()
- session.startup(sock)
- session.userauth_password('john', '******')
- channel = session.channel()
- channel.execute('ls -l')
- print channel.read(1024)
- import spur
- shell = spur.SshShell(hostname="localhost", username="bob", password="password1")
- result = shell.run(["echo", "-n", "hello"])
- print result.output # prints hello
- result = shell.run(["echo", "-n", "hello"], stdout=sys.stdout)
- import subprocess
- import sys
- HOST="IP"
- COMMAND="ifconfig"
- def passwordless_ssh(HOST):
- ssh = subprocess.Popen(["ssh", "%s" % HOST, COMMAND],
- shell=False,
- stdout=subprocess.PIPE,
- stderr=subprocess.PIPE)
- result = ssh.stdout.readlines()
- if result == []:
- error = ssh.stderr.readlines()
- print >>sys.stderr, "ERROR: %s" % error
- return "error"
- else:
- return result
- from ssh_decorate import ssh_connect
- ssh=ssh_connect('user','password','server')
- #Run a python function
- @ssh
- def python_pwd():
- import os
- return os.getcwd()
- print (python_pwd())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement