我对Python还不熟悉。我需要每天登录到服务器(桌面->;1.32->;0.20->;3.26)。为此,我需要打开putty并使用我正在登录的ssh连接。为此,我想用python编写一个脚本。
通过使用google,我认为subprocess.Popen可以做到这一点。但效果不好。
第一道:import subprocess
pid = subprocess.Popen("putty.exe user@xxx.xx.x.32 -pw password").pid
工作正常(打开窗口登录到.32)。但不能提供意见。我开始知道,要为同样的过程提供输入,我们需要使用管道。
第二道:from subprocess import Popen, PIPE, STDOUT
p = Popen("putty.exe user@xxx.xx.x.32 -pw password", stdout=PIPE, stdin=PIPE, stderr=STDOUT)
grep_stdout = p.communicate(input=b'ssh xx.xx.x.20\n')[0]
print(grep_stdout.decode())
通过使用这个,我也无法登录到第一个服务器。登录到所有服务器后,我需要终端保持活动状态。怎么做???
编辑
我需要在新的油灰窗里做这个。登录后不要关闭窗口。我有一些体力活要做。