Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ssh and quoting 1

Status
Not open for further replies.

columb

IS-IT--Management
Feb 5, 2004
1,231
EU
I'm writing a procedure in bash which copies files around a number of servers. As a basic check I'm running
Code:
ssh remote_host 'cd /remote/dir;ls | wc -l'
So far all well and good.
However some of the servers are only reachable via a double jump. i.e. to run a comand you have to run
Code:
ssh remote1 ssh remote2 command
For simple commands this works fine. However, as soon as I try passing complex commands like the one above I get all sorts of problems with the quoting. The simple
Code:
ssh remote1 ssh remote2 'cd /remote/dir;ls | wc -l'
drops the single quotes on remote1 and runs the cd on remote2 but the ls on remote1. I've tried things along the lines of escaping the quotes, quoting the escaped quotes, etc. but nothing is working.

My last resort is to encapsulate the commands and distribute them as executable files but...

Any help much appreciated.


On the internet no one knows you're a dog

Columb Healy
 
Can't say I've needed to do this myself so I'm not too conversant with the details but I suggest you look at ssh-agent which I believe would allow you to do your double-jump directly (i.e. as though it were a single jump).



Trojan.
 

Best would be to exchange ssh public keys between source server and remote2 and go one step.

Otherwise try this:
Code:
ssh remote1 "ssh remote2 'cd /remote/dir;ls | wc -l'"
[3eyes]



----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
LKBrwnDBA
I would love to go there directly but firewall rules, yada, yada... and the double jump is my only option.

Your code works perfectly

Thanks


On the internet no one knows you're a dog

Columb Healy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top