I have myfile.py
on my local machine.
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? Do I have to put
it onto whatever.com
?
You can first push your
myfile.py
to the remote machine usingfabric.operations.put
and then run the script like you've attempted to.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 manuallycd
into the remote folder usingfabric.context_managers.cd