LinuxQuestions.org
Help answer threads with 0 replies.
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 07-25-2011, 06:48 PM   #1
Drigo
Member
 
Registered: Jun 2009
Posts: 111

Rep: Reputation: 17
Angry Bash script using scp and ssh


So I want to access a directory that I copied first on scp (this directory will have many files on it). I will create a bash to do so but the problem comes when I want to access the folder I created since it will have only the lat subfolder name.

For example......


My bash script (MyScript.sh):
scp -r $1 xnat@10.45.4.43:/LOCATION/WHEREI/PUTTHEFILES/
ssh xnat@10.45.4.43 ' ls /home/xnat/xnat_Builds/$1'


From command line I'll execute:
./MyScript.sh /LOCATION/OF/MY/DIRECTORY/THAT/ILL/COPY

BUT THE PROBLEM IS THAT $1 on the second command (ssh) will have the entire folder tree ( /LOCATION/OF/MY/DIRECTORY/THAT/ILL/COPY) instead of just the last subfolder /COPY that will make me access it.


Any help?
 
Old 07-25-2011, 07:05 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
Your problem is that you've used 3 differently named(!) paths

1. $1 = /LOCATION/OF/MY/DIRECTORY/THAT/ILL/COPY
2. target = /LOCATION/WHEREI/PUTTHEFILES/
3. ls = /home/xnat/xnat_Builds/

I think what you want is
1. do a cd into the src dir ($1) before copying.
2. scp -r * xnat@10.45.4.43:sometarget
3. ssh xnat@10.45.4.43 'ls sometarget'

you may want to specify <sometarget> as $2.
If you want a specific subdir as the ls target under/within the scp target, specify as $3
 
Old 07-28-2011, 02:36 PM   #3
Drigo
Member
 
Registered: Jun 2009
Posts: 111

Original Poster
Rep: Reputation: 17
This wornt work becuase 'll be using this information to make a more complicated script. Is there a way to copy the directory withh all the directories on it though?

scp -???SOME OPTIONs??? /ALL/THESE/DIRECTORIES/AND/FOLDER myuser@myserver:/home/myuser/

So on the server machine my directory FOLDER is copied with all the subfolders such as:

on_my_server$ ls /home/myuser/ALL/THESE/DIRECTORIES/AND/FOLDER

NOT JUST:
on_my_server$ ls /home/myuser/FOLDER
 
Old 07-28-2011, 07:08 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
Basically
Code:
scp -r /ALL ...
Use the recursive switch, but you have to tell it the top of the tree you want copied, not the bottom....
 
Old 07-29-2011, 12:28 AM   #5
Drigo
Member
 
Registered: Jun 2009
Posts: 111

Original Poster
Rep: Reputation: 17
Well....I dont want to copy all the subfolder/directories that include there...i just want the entire address but the specific subfolder
 
Old 07-29-2011, 02:16 AM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
That's the same thing ...; there's no way to copy only the dir structure but without the files. Think about what the cmd is actually doing; it copies everything you tell it to ie (by default) the last element unless you specify recursive, in which case it starts from the first element, same as cp.
 
Old 08-05-2011, 06:04 AM   #7
jv2112
Member
 
Registered: Jan 2009
Location: New England
Distribution: Arch Linux
Posts: 719

Rep: Reputation: 103Reputation: 103
Lightbulb

I would check out rsync. It has many options you speak of.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Multiple scp/ssh in one bash script Lovelyhard Programming 13 07-31-2012 10:37 AM
bash script using sed/scp/ssh has issues with delimited file ScottThornley Programming 5 03-18-2009 04:45 PM
scp in bash script only getting to 11% just_me_then Linux - General 5 04-27-2008 04:02 AM
bash script problems: scp/ssh from the node of a cluster to the other server frankie_DJ Programming 2 01-27-2007 07:29 PM
Shell Script with ssh & scp ErikJohnson Linux - Networking 1 03-11-2004 05:14 PM


All times are GMT -5. The time now is 10:54 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration