Say there are 3 machine: 'local', 'A' and 'B'. Only 'local' and 'A' are connected and 'A' and 'B' are connected. And 'local' wants run commands on B via A.
# I run ssh A "ssh B commands" frequently, so a function is created for have clearer code.
run_on_B() {
ssh A "ssh B \"$@\""
}
run_on_B 'echo export PATH=\\\$HOME/bin:\\\$PATH >> \$HOME/.bash_profile'
Is there a better way to run commands on a remote machine via ssh? I feel it is easy to make mistake to do escaping $HOME
or $PATH
here.