Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import time
- import paramiko
- import os
- import cmd
- import datetime
- now = datetime.datetime.now()
- username = 'xxx'
- password = 'xxx'
- from zenoss import Zenoss
- zenoss = Zenoss('http://x.x.x.x:8080/', 'xx', 'xx')
- with open('/home/xxxx/hosts_all.txt', 'w') as f:
- for device in zenoss.get_devices()['devices']:
- print(device['name'], file=f)
- f.close()
- f = open('/home/xxxx/hosts_all.txt', 'r')
- read_f = f.readlines()
- f.close()
- for i in range(1, len(read_f)):
- remote_conn_pre = paramiko.SSHClient()
- remote_conn_pre.set_missing_host_key_policy(
- paramiko.AutoAddPolicy())
- remote_conn_pre.connect(read_f[i], username=username, password=password, look_for_keys=False, allow_agent=False)
- print("SSH connection established to %s" % read_f[i])
- remote_conn = remote_conn_pre.invoke_shell()
- print("Interactive SSH session established")
- list_of_comm = ["environment no moren", "admin display-confign"]
- for i in range(len(list_of_comm)):
- remote_conn.send(list_of_comm[i])
- time.sleep(2)
- output = remote_conn.recv(5000)
- filename = "%s_%.2i-%.2i-%i" % (read_f[i],now.day,now.month,now.year)
- print(str(output) + 'n', file=filename)
- Traceback (most recent call last):
- File "conf_backup.py", line 43, in <module>
- remote_conn_pre.connect(read_f[i], username=username, password=password, look_for_keys=False, allow_agent=False)
- File "/usr/local/lib/python3.4/dist-packages/paramiko/client.py", line 283, in connect
- to_try = list(self._families_and_addresses(hostname, port))
- File "/usr/local/lib/python3.4/dist-packages/paramiko/client.py", line 187, in _families_and_addresses
- addrinfos = socket.getaddrinfo(hostname, port, socket.AF_UNSPEC, socket.SOCK_STREAM)
- File "/usr/lib/python3.4/socket.py", line 533, in getaddrinfo
- for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
- socket.gaierror: [Errno -2] Name or service not known
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement