我想使用SSH来自动执行命令,但是当它运行时会出现一条消息,键入是或否。可以在一行命令中或在paramiko中以某种方式回答此消息。
我尝试了很多类似的事情。
sudo /usr/sbin/service-maintenance-window ; yes
sudo /usr/sbin/service-maintenance-window | yes
yes | sudo /usr/sbin/service-maintenance-window
yes | sudo /usr/sbin/service-maintenance-window
代码如下:
from paramiko import SSHClient
import paramiko
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect("xxxx", username="xxxx", password="xxxx",timeout=5)
stdin,stdout,stderr = ssh.exec_command("yes | sudo /usr/sbin/service-maintenance-window")
print(stdout.read())
我要接受的消息是:
------------------------------ WARNING ---------------------------------------
You are about to be granted temporary privileged shell access of VPLEX
to perform advanced maintenance or servicing tasks.
As this shell has higher privileges, non-expert usage of this shell can
result in damage to your VPLEX as well as compromising of various
security features.
Respond Yes only if you are authorized and qualified to perform advanced
VPlex maintenance and/or servicing.
Make sure to:
1 - limit your use of this shell to only those items
that require this level of elevated privilege.
2 - exit this elevated privilege shell when you have finished using it.
-------------------------------------------------------------------------------
Are you sure you want to continue ? [Yes/No]: