在ssh远程上执行python autogui脚本在ssh主机上执行命令

时间:2019-06-23 09:41:34

标签: python linux python-3.x ssh subprocess

我试图在我的Pi上通过ssh执行python脚本。我已经设置了我的Priv / Pub密钥,并通过在主机上使用python脚本来执行它们:

subprocess.run('ssh -p 2222 john@<IP_of_Pi> python3 /home/john/test.py', shell=True)

我正在尝试通过使用autogui使某些事情自动化。我的基本脚本如下:

import pyautogui as aut

aut.PAUSE = 1
aut.keyDown('ctrl')
aut.keyDown('alt')
aut.press('t')
aut.keyUp('alt')
aut.keyUp('ctrl')
aut.typewrite(['f','i','r','e','f','o','x','enter'])
aut.hotkey('alt','d')
aut.typewrite(['d','u','c','k','d','u','c','k','g','o','.','c','o','m','enter'])

我的问题是我执行的所有命令都在本地主机上运行。如果我使用其他自动化框架,例如硒。我打开的每个浏览器不是在Pi上启动,而是在主机上启动。

我尝试了子流程的几种修改,例如

subprocess.run(['ssh','-p','2222 ','john@<IP_of_Pi>', 'python3', /home/john/test.py'])
subprocess.run(['ssh','-p','2222 ','john@<IP_of_Pi>', 'python3', /home/john/test.py'],shell=True,stdout=subprocess.PIPE)
subprocess.Popen(['ssh','-p','2222 ','john@<IP_of_Pi>', 'python3', /home/john/test.py'])
...

如果我在外壳程序中执行test.py,则可以重新执行错误,浏览器仍在主机上打开。

以防万一,我的遥控器(Pi)上的ssh_config:

Host *
#   ForwardAgent no
#   ForwardX11 no
#   ForwardX11Trusted yes
#   PasswordAuthentication yes
#   HostbasedAuthentication no
#   GSSAPIAuthentication no
#   GSSAPIDelegateCredentials no
#   GSSAPIKeyExchange no
#   GSSAPITrustDNS no
#   BatchMode no
#   CheckHostIP yes
#   AddressFamily any
#   ConnectTimeout 0
#   StrictHostKeyChecking ask
#   IdentityFile ~/.ssh/id_rsa
#   IdentityFile ~/.ssh/id_dsa
#   IdentityFile ~/.ssh/id_ecdsa
#   IdentityFile ~/.ssh/id_ed25519
#   Port 22
#   Protocol 2
#   Ciphers aes128-ctr,aes192-ctr,aes256-ctr,aes128-cbc,3des-cbc
#   MACs hmac-md5,hmac-sha1,umac-64@openssh.com
#   EscapeChar ~
#   Tunnel no
#   TunnelDevice any:any
#   PermitLocalCommand no
#   VisualHostKey no
#   ProxyCommand ssh -q -W %h:%p gateway.example.com
#   RekeyLimit 1G 1h
    SendEnv LANG LC_*
    HashKnownHosts yes
    GSSAPIAuthentication yes

0 个答案:

没有答案