python - 对 paramiko ssh 上的命令是否有可能回答是/否?
问题描述
我想使用 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]:
解决方案
推荐阅读
- objective-c - 与 NSTimer 一起使用时,cellForRowAtIndexPath 无法正确呈现单元格
- laravel-5.5 - Laravel 5.5 中的时间验证
- ios - 此捆绑包无效 - /Payload/MyAppName.app/Sticker Pack.stickerpack 的 Info.plist 文件丢失或无法读取
- sql - 如何在 SQL 查询中替换当前时间戳
- docker - Docker Compose 使用缓存构建命令并且在复制到 docker 时不拾取更改的文件
- ios - Swift Popup 返回值到父视图控制器
- php - PDO 读取数据库,但不登录系统
- r - 如何通过修改后的停止调用获得正确的环境打印输出
- java - 如何打印具有特定长度的所有单词以及该长度的乘积
- ms-access - 当它是一个 Make Table 查询时,DSum 查询很慢