我尝试过的:
invoke_shell()然后channel.send su发送密码导致不是rootinvoke_shell()然后channel.exec_command导致"频道关闭"错误_transport.open_session()然后channel.exec_command导致不是根invoke_shell() 然后写入stdin并冲洗它导致不是root我的 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)