通过Python脚本执行交互式SSH命令

2024-04-19 01:58:18 发布

您现在位置:Python中文网/ 问答频道 /正文

I am trying to automate to collect the logs from the Cisco Call Manager via CLI by using the from paramiko_expect import SSHClientInteraction where I am not able to send the interactive command to the server. 

While trying to download the logs, it will ask information like SFTP IP address, username, password and directory which needs to send an interactive command.

每当代码运行时,它都会在交互式命令部分停止,因为python脚本在此处停止,所以不会将命令发送到服务器。需要知道有没有其他方法来编码这些需求。在

^{pr2}$

在++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 下面是python脚本的输出。在

there is no error message but it stops at Would you like to proceed [y/n]?  here

Command Line Interface is starting up, please wait ...

   Welcome to the Platform Command Line Interface

VMware Installation:
    4 vCPU: Intel(R) Xeon(R) Platinum 8180 CPU @ 2.50GHz
    Disk 1: 110GB, Partitions aligned
    6144 Mbytes RAM

admin:file get activelog /syslog/AlternateSyslog
Please wait while the system is gathering files info ...
 Get file: active/syslog/AlternateSyslog
done.
Sub-directories were not traversed.
Number of files affected: 1
Total size in Bytes: 2261400
Total size in Kbytes: 2208.3984
Would you like to proceed [y/n]?

Tags: thetofrom命令脚本sendisnot
1条回答
网友
1楼 · 发布于 2024-04-19 01:58:18

您可以尝试在程序开始时添加全局配置命令“fileprompt quiet”,然后再发送任何其他命令。这将禁止任何是/否问题,并将其自动设置为默认值。只需确保在代码结束时,使用“文件提示警报”将其关闭,以防止以后发生任何令人讨厌的意外。在

这在大多数Cisco IOS平台上都能工作,如果CUCM中的命令不同,我相信会有一个等效的命令来执行相同的操作。在

相关问题 更多 >