Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- servers=["192.168.1.1","192.168.1.2"]
- class sshClient:
- def __init__(self,host):
- self.client = paramiko.SSHClient()
- self.client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
- try:
- self.client.connect(host,username="account", password="password")
- except paramiko.SSHException:
- print "Connection Error"
- def close(self):
- if self.client is not None:
- self.client.close()
- self.client = None
- def execute(self, command):
- stdin, stdout, stderr = self.client.exec_command(command)
- output=''.join(stdout.readlines())
- return output
- class myClass(unittest.TestCase):
- def test_test1(self):
- self.assertRegexpMatches(_ssh.execute('netstat -nlp | grep -vi unix | grep sshd'),'sshd','sshd not running')
- if __name__ == '__main__':
- for server in servers:
- _ssh = sshClient(server)
- hostname = _ssh.execute('hostname')
- hostname = hostname.replace("n","")
- print hostname
- runner = unitest.TextTestRunner()
- unittest.main(testRunner=runner,exit=False)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement