Last active
November 9, 2015 06:53
-
-
Save oiuww09fn/ac74376d3335b50771b2 to your computer and use it in GitHub Desktop.
Running command on remote machine.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
from paramiko import SSHClient, AutoAddPolicy | |
class RemoteCMD(object): | |
def __init__(self): | |
self.client = None | |
def ssh_connect(self, server=None, username="", password=""): | |
if server is None: | |
raise RuntimeError("Server could not be None") | |
self.client = SSHClient() | |
self.client.set_missing_host_key_policy(AutoAddPolicy()) | |
self.client.connect(server, username=username, password=password) | |
def run_cmd(self, cmd): | |
"""""" | |
stdin, stdout, stderr = self.client.exec_command(cmd) | |
return stdout.read() | |
if __name__ == "__main__": | |
a = RemoteCMD() | |
a.ssh_connect("192.168.1.101", "username", "password") | |
print a.run_cmd("ls /tmp/") | |
print a.run_cmd("ls /var/") | |
print a.run_cmd("pwd") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment