我的 ShoreTel 语音开关出现问题,我正在尝试使用 Paramiko 跳入其中并运行几个命令。我认为问题可能在于 ShoreTel CLI 给出的提示与标准 Linux 不同$。它看起来像这样:
server1$:stcli
Mitel>gotoshell
CLI> (This is where I need to enter 'hapi_debug=1')
Run Code Online (Sandbox Code Playgroud)
Python 是否仍然期待这一点$,还是我错过了其他东西?
我认为这可能是一个时间问题,所以我把它们放在time.sleep(1)命令之间。看来还是没拿。
import paramiko
import time
keyfile = "****"
User = "***"
ip = "****"
command1 = "stcli"
command2 = "gotoshell"
command4 = "hapi_debug=1"
ssh = paramiko.SSHClient()
print('paramikoing...')
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(hostname = ip, username = User, key_filename = keyfile)
print('giving er a go...')
ssh.invoke_shell()
stdin, stdout, stderr = ssh.exec_command(command1)
time.sleep(1)
stdin, stdout, stderr …Run Code Online (Sandbox Code Playgroud) 从事此工作已经有一段时间了,我在此站点上未找到任何示例,也未找到任何其他相关的示例。我有一个列表,我想做的很简单。我只需要搜索该列表以找到关键字“ Buffer Log”。找到该关键字后,我需要打印该行的每一行,直到列表末尾。任何方向都将不胜感激。看来我已经很接近了。
logfile = open('logs.txt', 'r')
readlog = logfile.readlines()
logfile.close()
lines = []
for line in readlog:
lines.append(line)
for x in lines:
if "Log Buffer" in x:
z =lines.index(x)
print(lines[z:]
Run Code Online (Sandbox Code Playgroud)