相关疑难解决方法(0)

如何用paramiko运行sudo?(蟒蛇)

我尝试过的:

  1. invoke_shell()然后channel.send su发送密码导致不是root
  2. invoke_shell()然后channel.exec_command导致"频道关闭"错误
  3. _transport.open_session()然后channel.exec_command导致不是根
  4. invoke_shell() 然后写入stdin并冲洗它导致不是root

python ssh sudo paramiko

14
推荐指数
3
解决办法
3万
查看次数

在 Python Paramiko 中的 SSH 服务器上的辅助 shell/命令中执行(子)命令

我的 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)

python ssh paramiko shoretel

3
推荐指数
1
解决办法
1998
查看次数

标签 统计

paramiko ×2

python ×2

ssh ×2

shoretel ×1

sudo ×1