Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- naveen@ol4:>vi second.py
- naveen@ol4:>clear
- naveen@ol4:>cat second.py
- #!/usr/bin/env python
- import paramiko
- class Servers(object):
- def __init__(self,hostname,cmd):
- self.hostname=hostname
- ssh=paramiko.SSHClient()
- ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
- ssh.connect(hostname,username="root",password="redhat")
- stdin,stdout,stderr=ssh.exec_command(cmd)
- print stdout.readlines()
- ssh.close()
- naveen@ol4:>python
- Python 2.7.5 (default, Sep 5 2016, 02:30:38)
- [GCC 4.8.5 20150623 (Red Hat 4.8.5-9)] on linux2
- Type "help", "copyright", "credits" or "license" for more information.
- >>> import second
- >>> a=second.Servers('puppet','hostname')
- [u'puppet.localdomain\n']
- >>> a=second.Servers('puppet','cat /etc/hosts')
- [u'# HEADER: This file was autogenerated at 2016-12-17 09:41:55 +0530\n', u'# HEADER: by puppet. While it can still be managed manually, it\n', u'# HEADER: is definitely not recommended.\n', u'127.0.0.1\tlocalhost\tlocalhost.localdomain localhost4 localhost4.localdomain4\n', u'::1\tlocalhost\tlocalhost.localdomain localhost6 localhost6.localdomain6\n', u'10.0.2.24\tpuppet\tpuppet.localdomain\n', u'10.0.2.9\trhel1\trhel1.localdomain\n', u'10.0.2.21 ol4 ol4.localdomain\n', u'10.0.2.37\tol1\tol1.localdomain\n']
- >>> a=second.Servers('puppet','facter fqdn')
- [u'puppet.localdomain\n']
- >>> hostlist=['rhel1','puppet','jenkins']
- >>> for host in hostlist:
- ... a=second.Servers(host,'hostname')
- ...
- naveen@ol4:>vi second.py
- naveen@ol4:>clear
- naveen@ol4:>cat second.py
- #!/usr/bin/env python
- import paramiko
- class Servers(object):
- def __init__(self,hostname,cmd):
- self.hostname=hostname
- ssh=paramiko.SSHClient()
- ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
- ssh.connect(hostname,username="root",password="redhat")
- stdin,stdout,stderr=ssh.exec_command(cmd)
- print stdout.readlines()
- ssh.close()
- naveen@ol4:>python
- Python 2.7.5 (default, Sep 5 2016, 02:30:38)
- [GCC 4.8.5 20150623 (Red Hat 4.8.5-9)] on linux2
- Type "help", "copyright", "credits" or "license" for more information.
- >>> import second
- >>> a=second.Servers('puppet','hostname')
- [u'puppet.localdomain\n']
- >>> a=second.Servers('puppet','cat /etc/hosts')
- [u'# HEADER: This file was autogenerated at 2016-12-17 09:41:55 +0530\n', u'# HEADER: by puppet. While it can still be managed manually, it\n', u'# HEADER: is definitely not recommended.\n', u'127.0.0.1\tlocalhost\tlocalhost.localdomain localhost4 localhost4.localdomain4\n', u'::1\tlocalhost\tlocalhost.localdomain localhost6 localhost6.localdomain6\n', u'10.0.2.24\tpuppet\tpuppet.localdomain\n', u'10.0.2.9\trhel1\trhel1.localdomain\n', u'10.0.2.21 ol4 ol4.localdomain\n', u'10.0.2.37\tol1\tol1.localdomain\n']
- >>> a=second.Servers('puppet','facter fqdn')
- [u'puppet.localdomain\n']
- >>> hostlist=['rhel1','puppet','jenkins']
- >>> for host in hostlist:
- ... a=second.Servers(host,'hostname')
- ...
Add Comment
Please, Sign In to add comment