简体   繁体   English

Fabric可以在远程计算机上运行本地脚本吗?

[英]Can fabric run a local script on a remote machine?

I have myfile.py on my local machine. 我的本地机器上有myfile.py

I want to do something like: 我想做的事情如下:

from fabric.api import env, run

env.host_string = 'whatever.com'

def run_script():
    run('python myfile.py')

but of course, this returns can't open file 'myfile.py': [Errno 2] No such file or directory How can I run this file remotely? 但当然,这个返回can't open file 'myfile.py': [Errno 2] No such file or directory如何远程运行这个文件? Do I have to put it onto whatever.com ? 我必须put它放到whatever.com吗?

You can first push your myfile.py to the remote machine using fabric.operations.put and then run the script like you've attempted to. 您可以先使用fabric.operations.putmyfile.pymyfile.py远程计算机,然后像您尝试的那样运行脚本。

But make sure the path to your script is either an absolute path or relative to the current directory from which the remote commands are being executed, this can be found out using cwd you can also manually cd into the remote folder using fabric.context_managers.cd 但要确保脚本的路径是绝对路径或相对于执行远程命令的当前目录的相对路径,这可以使用cwd找到,您也可以使用fabric.context_managers.cd手动cd到远程文件夹中fabric.context_managers.cd

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM