[NTLUG:Discuss] ssh and command macros

Kevin Brannen kbrannen at pwhome.com
Sat Mar 12 17:02:11 CST 2005


Jack Snodgrass wrote:

>I know I can do something like
>ssh remote_host "cd /tmp; ls -lart"
>and it will connect me to remote_host, cd to the /tmp directory and then 
>run the ls -lart command. when it's done, it disconnects me and I end
>up back where I started. 
>
>How can I do something like 
>ssh remote_host "cd /tmp" 
>and end up in the /tmp directory on the remote_host? I don't want 
>to just run the command and exit. 
>
>In my scenario... I may find myself on hostA in /build/dir/1. I want to 
>be on hostB in that same directory. So... I want to ssh hostB but 
>get dumped into /build/dir/1 instead of the 'home' directory. 
>
>Does anyone have any ideas? Is there a ssh option I missed 
>to run a command and stay logged into the remote host? 
>  
>

How about:

ssh remote_host
cd /tmp
...whatever...
:-)

Or try:

ssh remote_host "cd /tmp; sh"

I haven't tried it, but it seems like it should work.

Kevin




More information about the Discuss mailing list