LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-29-2009, 05:14 PM   #1
knghtz
LQ Newbie
 
Registered: Aug 2009
Posts: 4

Rep: Reputation: 0
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.
 
Old 09-29-2009, 05:20 PM   #2
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,836
Blog Entries: 1

Rep: Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251
Can you post your script, please?
 
Old 09-29-2009, 05:28 PM   #3
knghtz
LQ Newbie
 
Registered: Aug 2009
Posts: 4

Original Poster
Rep: Reputation: 0
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.
 
Old 09-29-2009, 05:51 PM   #4
lutusp
Member
 
Registered: Sep 2009
Distribution: Fedora
Posts: 835

Rep: Reputation: 102Reputation: 102
Quote:
Originally Posted by knghtz View Post
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.
 
Old 09-29-2009, 05:57 PM   #5
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,836
Blog Entries: 1

Rep: Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251
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

Last edited by sycamorex; 09-29-2009 at 05:58 PM.
 
Old 09-29-2009, 06:16 PM   #6
knghtz
LQ Newbie
 
Registered: Aug 2009
Posts: 4

Original Poster
Rep: Reputation: 0
Ah that makes sense, ha! :/

I have it working now, thanks guys!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
ssh-agent, ssh-add and ssh-keygen AND CVS raylpc Linux - General 2 11-19-2008 02:50 AM
LXer: ssh-xfer: Quickly grabbing files over an existing SSH connection LXer Syndicated Linux News 0 08-08-2008 03:11 PM
setting up an ssh soxy or local ssh tunnel from within an ssh soxy Mangenius Linux - Networking 0 03-05-2007 03:15 PM
Passwordless SSH with SSH commercial server and open ssh cereal83 Linux - General 7 04-18-2006 12:34 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:59 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration