paramiko invoke_shell抓交换机配置时有more怎么处理
时间: 2023-07-31 21:09:53 浏览: 481
当使用paramiko的invoke_shell方法连接交换机,并抓取交换机配置时出现more的情况,可以通过以下两种方式来处理:
1. 使用send方法发送空格键,来翻页:
```
channel = ssh.invoke_shell()
channel.send('terminal length 0\n') # 设置交换机的分页长度为0,避免出现more提示
channel.send('show running-config\n') # 执行抓取配置的命令
time.sleep(2)
while channel.recv_ready():
channel.recv(1024)
channel.send(' ') # 发送空格键,翻页
time.sleep(2)
while channel.recv_ready():
channel.recv(1024)
```
2. 使用exec_command方法执行抓取配置的命令,并将结果通过recv方法获取:
```
channel = ssh.invoke_shell()
channel.send('terminal length 0\n') # 设置交换机的分页长度为0,避免出现more提示
stdin, stdout, stderr = ssh.exec_command('show running-config') # 执行抓取配置的命令
time.sleep(2)
while channel.recv_ready():
channel.recv(1024)
output = stdout.read().decode('utf-8') # 获取命令执行的结果
```
阅读全文
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)