我試圖運行腳本來顯示所有配置,並將它們寫入juniper和CISCO路由器的文件中。 到目前爲止,CISCO腳本的工作原理與Juniper路由器一樣。Python Exscript - JunOS
for ii in JUNIPER:
print ii
cmd2 = 'show configuration | display set'
conn.connect(ii)
conn.login(account1)
conn.execute(cmd2)
print conn.response
#filerouter = open(ii, "w")
#filerouter.write(conn.response)
#filerouter.close()
獲得設備列表查詢後,我跑這一點,但它卡住彷彿有緩衝的限制... -
如果我試圖做一個不同的命令:
("show configuration | display set | match destination ")
- 我得到寫在文件或屏幕上的輸出。
C:\Python27>python.exe C:\User\suserrr\Downloads\shrun.py
'clear' is not recognized as an internal or external command,
operable program or batch file.
Generating configs for ROUTER: R1.test.site
Generating connect for ROUTER: R2.test.site
==============
===========
routername
Traceback (most recent call last):
File "C:\Users\userrr\Downloads\shrun.py", line 40, in <module>
conn.execute(cmd2)
File "C:\Python27\lib\site-packages\exscript-2.1.440-py2.7.egg\Exscript\protocols\Protocol.py", line 900, in execute
return self.expect_prompt()
File "C:\Python27\lib\site-packages\exscript-2.1.440-py2.7.egg\Exscript\protocols\Protocol.py", line 999, in expect_prompt
result = self.expect(self.get_prompt())
File "C:\Python27\lib\site-packages\exscript-2.1.440-py2.7.egg\Exscript\protocols\Protocol.py", line 980, in expect
result = self._expect(prompt)
File "C:\Python27\lib\site-packages\exscript-2.1.440-py2.7.egg\Exscript\protocols\Protocol.py", line 956, in _expect
result = self._domatch(to_regexs(prompt), True)
File "C:\Python27\lib\site-packages\exscript-2.1.440-py2.7.egg\Exscript\protocols\SSH2.py", line 329, in _domatch
if not self._fill_buffer():
File "C:\Python27\lib\site-packages\exscript-2.1.440-py2.7.egg\Exscript\protocols\SSH2.py", line 303, in _fill_buffer
raise TimeoutException(error)
Exscript.protocols.Exception.TimeoutException: Timeout while waiting for response from device
=========== ====問題 - 如何讓腳本運行,並提供命令的輸出:show configuration | display set
第二PIC顯示錯誤我得到但是如果我將命令更改爲:show configuration | display set | match description
,我會收到請求的信息。我是否缺少在模塊中添加一些內容,以便exscript/python避免超時?
謝謝約翰 - 這正是這裏發生了什麼。我將很快嘗試 –
約翰!你是男人 - 它像魅力一樣工作。大約30天后,我進入了JunOS,仍然在學習通過它的方式。我知道思科我的命令終端長度爲0 ... –
是的,Exscript有內置的「連接器」後端,當你連接到一個思科設備時,應該自動爲你設置「term len 0」。但對於JunOS,我不確定是否有辦法在VTY會話級別禁用分頁,就像在思科設備上一樣。 –