remote-script-exec
remote-script-exec
When a command for a remote node is anything more than a trivial one-liner, do not inline it into the ssh command string. Write the script locally, scp it over, execute it there. The local file is the source of truth; the remote copy is disposable.
The pattern
# 1. write locally (node-prefixed name, see conventions below)
# ~/tmp/<node>_<task>.py
# 2. upload and run
scp -o StrictHostKeyChecking=no ~/tmp/<node>_<task>.py <user>@<node>:/tmp/
ssh <user>@<node> 'python3 /tmp/<node>_<task>.py 2>&1'
Iterate by editing the local file, re-scp, re-run. Never patch the remote copy in place — the next iteration would clobber the fix.
Inline ssh is fine only for a single command with no nested quotes and no multi-statement chaining (ssh <node> 'ls /tmp'). Everything else — loops, pipes with quotes, python one-liners, heredocs, anything you would write across lines — goes through the pattern. On unfamiliar nodes the first connect may need -o StrictHostKeyChecking=no; on later connects drop it once the host key is known.