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? |
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 |
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 |
Basically
Code:
scp -r /ALL ... |
Well....I dont want to copy all the subfolder/directories that include there...i just want the entire address but the specific subfolder
|
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.
|
I would check out rsync. It has many options you speak of.
|
All times are GMT -5. The time now is 08:27 AM. |