如何使用 python (paramiko) 在 root 中 运行 多命令
How to run multi-commands in root using python (paramiko)
我正在尝试 运行 在 root 用户中执行两个命令。 command_1 在 root 中 运行ning,command_2 在 root 之外 运行ning。
import paramiko
import sys
import os
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('hostname', username='username',password='password')
stdin, stdout, stderr = ssh.exec_command("sudo -i command_1 command_2")
output = stdout.read()
print output
我试过stdin, stdout, stderr = ssh.exec_command("sudo -i command_1;command_2")
但没有用。
使用“&”运算符应该可以。
stdin, stdout, stderr = ssh.exec_command("sudo -i command_1 & sudo -i command_2")
我正在尝试 运行 在 root 用户中执行两个命令。 command_1 在 root 中 运行ning,command_2 在 root 之外 运行ning。
import paramiko
import sys
import os
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('hostname', username='username',password='password')
stdin, stdout, stderr = ssh.exec_command("sudo -i command_1 command_2")
output = stdout.read()
print output
我试过stdin, stdout, stderr = ssh.exec_command("sudo -i command_1;command_2")
但没有用。
使用“&”运算符应该可以。
stdin, stdout, stderr = ssh.exec_command("sudo -i command_1 & sudo -i command_2")