単純にローカルのスクリプトをリモートで実行したいなら、sshを使えばいいです。
ssh user@host 'bash -s' < local_script.sh > results.txt
コマンドの引数を渡したいとか、環境変数を引き継ぎたいとかになると、もう一工夫必要でしょう。
fabricを使うなら,下のコードをfabfile.pyに保存してfab remote:ホスト名,ローカルスクリプト名
として実行すれば動きます。
from fabric.api import run, settings
def remote(host, local_script):
# read the local script
with open(local_script, 'rb') as f:
script = f.read()
# run it on the remote host
with settings(host_string=host):
resp = run(script)
# save the result into results.txt
with open('results.txt', 'wb') as f:
f.write(resp)