1
gnozix 2020-10-23 13:42:46 +08:00 1
感觉你需要的是 ansible
|
2
zydxn 2020-10-23 13:44:43 +08:00 1
之前用 paramiko 做过类似的事情
client = paramiko.SSHClient() client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) client.connect(hostname, ssh_port, username=username, password=password) transport = client.get_transport() sftpClient = paramiko.SFTPClient.from_transport(transport) # 传输 sftpClient.put(localpath, remotepath, callback=your_call_back) client.close() |
3
MoYi123 2020-10-23 13:46:00 +08:00 2
用 expect 就行了
#!/usr/bin/expect spawn ssh root@{host} -p {port} expect "{host}'s password: " send "{password}" interact 这是 ssh 的例子 |
4
huangmingyou 2020-10-23 13:46:04 +08:00 1
ssh 有参数忽略主机 key 认证,另外用密钥文件替代口令。
|
5
wwqgtxx 2020-10-23 13:47:46 +08:00
是可以的,不过你需要用 subprocess.Popen 去完成交互
|
6
smallpython OP @MoYi123
@huangmingyou 我想问的是有没有什么方法可以让程序自己输入, 而不是绕开输入, 因为如果绕开的话, 虽然功能解决了, 但是还是不知道怎么让 Python 自己去填写这个信息 |
7
smallpython OP @wwqgtxx 能给个具体例子吗?我自己测试 stdin.write()方法只有在本地命令才会生效, 涉及到这种两台机器交互的情况就没用了, 还是会让我手动输入密码
|
8
tony9413 2020-10-23 13:56:05 +08:00
paramiko 正解,如果不会,可以试试 robot 封装的[SSHLibrary]( http://robotframework.org/SSHLibrary/)
|
9
bairdshi 2020-10-23 15:26:16 +08:00
我之前研究了许久 fanric 是最佳解 其他都是垃圾
|
11
bairdshi 2020-10-23 15:32:24 +08:00 1
from fabric import task, Connection
from invoke.tasks import call # r represents raspberry pi name_ip_mapping = {"r1": "192.168.122.3", "r2": "192.168.122.2", "r3": "192.168.122.7", "camera": "192.168.122.55"} ip_name_mapping = {v: k for k, v in name_ip_mapping.items()} @task def scp1(c): """ copy scripts to raspberry pi 1 """ c = Connection(name_ip_mapping["r1"], user='pi', connect_kwargs={'password': 'xxxx'}) c.put('r1/main.py', "r1") c.put('r1/config.py', "r1") c.put('r1/part.py', "r1") c.put('r1/logger.py', "r1") |
12
wangyzj 2020-10-23 15:33:26 +08:00
paramiko
|
13
css3 2020-10-23 15:33:45 +08:00
把 a.txt 复制到 100 台服务器上, 这还不用 ansible ???
|
14
CallMeReznov 2020-10-23 15:46:22 +08:00
paramiko
|