I need ideas to create a way to remotely do (any) commands through multiples hops. The main problem is that the number of intermediary hops is variable! So I need 1) to describe the "topology" of the servers, and then 2) have a function?/script that can execute some commands on all of them, using the intermediary hops as needed to reach the final destination.
exemple of topology: (but this varies too)
server A communicates with server B directly. servers C and D are "behind" B. server E is behing C etc.... (many servers, many indirect ways to reach some of them, some have multiple ways) Then from A, you can execute "some command" on E with: ssh foo@B ssh bar@C ssh baz@E "some command" or you can build intermediary tunnels connecting A to **C** and then: ssh -P 1234 baz@E "some command"
I have a few "main hop" that can reach a lot of servers directly
I want to be able to do a (potentially complex) command on all 5 servers, via a not-too-complex command, allowing me to (in a script) do something like
do_on_all_servers "for dir in /something* ; do cd \"\$dir\" && something using $thisLOCALvariable ; done" # with an easy way to say "from X, ssh to specificuser@Y using this ssh command and this username" to describe each intermediary hops # dir is a remote variable, thisLOCALvariable is at the initiating script level, and the amount of "\" needs to be adjusted if going through multiple hops...
Additional constraint: no GNU tools, no "nc", just plain (very) old ssh & awk & similar old tools, to have a portable way. Portability must be high (use of nifty ">1990?" options and tools must be avoided). And I would prefer not have to do this by copying a script over the final destination & ssh via multiple hops that script, but this can be ok if you think it's simpler/better.
Right now I'm using variables to concatenete ssh's .... but this doesn't help for the how-many-"\"-do-I-need problem.
My idea include: stringing variables containing a "shh user@host" together. Or maybe using this very neat https://stackoverflow.com/a/15198031/1841533 tunneling way, which if I can do it properly allow to do scp, etc using the proper local port to reach the final destination "directly" (but not sure that this way is available on all hops).