LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   cd after ssh (https://www.linuxquestions.org/questions/linux-newbie-8/cd-after-ssh-758534/)

knghtz 09-29-2009 05:14 PM

cd after ssh
 
Hi all,

sorry if this question has been answered numerous times before, I can't seem to find an answer anywhere. I have created a bash script here that should ssh into a server, cd to a directory and scp certain files into another server. For some reason, after I ssh into the server (we have keys installed so don't need the passwords) it just sits there. I try to pwd after the ssh but nothing happens, it just sits there after the ssh like it's waiting for me to do something. Is there some additional step I'm missing? I can't seem to find anything on the net that states otherwise.

Thanks.

sycamorex 09-29-2009 05:20 PM

Can you post your script, please?

knghtz 09-29-2009 05:28 PM

Sorry I guess that would help:

#!/bin/sh
path='/path/to/go/to'
ssh name@server
cd $path
scp blah blah
.
.

The problem is once it gets onto the server it just stops there. I threw a pwd after the ssh to verify but it doesn't do that either. I'm sure it's a simple fix I'm just having problems locating an answer.

Thanks.

lutusp 09-29-2009 05:51 PM

Quote:

Originally Posted by knghtz (Post 3701005)
Sorry I guess that would help:

#!/bin/sh
path='/path/to/go/to'
ssh name@server
cd $path
scp blah blah
.
.

The problem is once it gets onto the server it just stops there. I threw a pwd after the ssh to verify but it doesn't do that either. I'm sure it's a simple fix I'm just having problems locating an answer.

Thanks.

But the commands in your script aren't executed remotely, they are executed locally -- but only after the script exits the "ssh" line.

Did you think the script was transferred to the remote server and executed its remaining lines there?

Try this example:

Code:

echo "line 1: located at `hostname`"
ssh name@server
echo "Line 3: located at `hostname`"

This script gets to line 2, logs onto the remote server, and awaits your input. If you exit the remote session, you will see line 3 get printed -- locally.

sycamorex 09-29-2009 05:57 PM

Why dont you use the following:
Code:

remote_path=/remote/path/
local_path=/local/path/
scp remote_user@remote_host:$remote_path/file $local_path


knghtz 09-29-2009 06:16 PM

Ah that makes sense, ha! :/

I have it working now, thanks guys!


All times are GMT -5. The time now is 02:36 PM.