LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Bash script using scp and ssh (https://www.linuxquestions.org/questions/linux-newbie-8/bash-script-using-scp-and-ssh-893721/)

Drigo 07-25-2011 05:48 PM

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?

chrism01 07-25-2011 06:05 PM

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

Drigo 07-28-2011 01:36 PM

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

chrism01 07-28-2011 06:08 PM

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....

Drigo 07-28-2011 11:28 PM

Well....I dont want to copy all the subfolder/directories that include there...i just want the entire address but the specific subfolder

chrism01 07-29-2011 01:16 AM

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.

jv2112 08-05-2011 05:04 AM

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


All times are GMT -5. The time now is 08:27 AM.