Python で Cisco のログを取得
Python で Cisco のログを収集する際のスクリプト例です。
Exscript で上手くいかずハマってしまったため、とりあえず Paramiko を使用しました。
"ssh.exec_command" で複数のコマンドを実行できないため、少し不便です。(方法があるかもですが。。)
import paramiko import datetime, time import cmd import sys hostname = 'myrouter' ipaddress = '192.168.1.1' username = 'username' password = 'password' date = datetime.date.today().strftime("%Y-%m-%d") ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect(ipaddress, username=username, password=password) stdin, stdout, stderr = ssh.exec_command('show tech-support unprivileged') # print stdout.read() open_file = stdout.read() config_file = open(hostname+"-"+date+".cfg","w") config_file.write(open_file) config_file.close() ssh.close() print "Finished python wrote "+hostname+"-"+date+".cfg"
参考書籍
リンク
以上