The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
copying directories from NT server to Unix server (solaris 5.8) jhmr7 UNIX for Dummies Questions & Answers 4 08-07-2008 10:53 PM
Copying multiple folders to local machine (don't know folder names) leenyburger UNIX for Dummies Questions & Answers 5 06-12-2008 04:38 AM
decompressed files to specific folders c00kie88 Shell Programming and Scripting 3 04-06-2008 02:41 PM
Copying specific files faaron3 UNIX for Dummies Questions & Answers 3 03-24-2008 10:59 AM
Copying Folders without some folders... ;-) chimpu UNIX for Dummies Questions & Answers 5 04-26-2004 09:25 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 12-18-2007
Registered User
 

Join Date: Apr 2006
Posts: 74
Copying specific folders from one server to another

Hey Guys,

After doing some searching on google i still cannot find a specific answer. May be its because my lack of skills in unix. If ayone can help me out or give me a psuedo code i really appreciate it.

I have one unix server ABC. The folders which i am trying to access is :-
/home/web/dummy. Now in dummy folder i might have 2 or 5 different folders something like this:

/home/web/dummy/mike/images
/home/web/dummy/mike/source
/home/web/dummy/mike/testing

/home/web/dummy/john/images
/home/web/dummy/john/source
/home/web/dummy/john/testing

/home/web/dummy/alex/images
/home/web/dummy/alex/source

As you can see under dummy folders i have 3 different folders. But the folder which i am concern about is (testing) folder. So mike and john have testing folder, images and source. I would like to write a script which will have a path of :-

/home/web/dummy

after dummy it will check each and every directory. so first is john it will see if john has testing folder. if john have testing folder then it will copy to my another unix server which is XYZ. So in server XYZ i would like to store the files over here :-

/home/manage/

so if john contains the folder testing then it will copy to my XYZ server :-

/home/manage/john/testing

As you can see i dont want to copy images or source folder. People with testing folder will be only copied. Any guidance on how to achieve it. I know the command tocopy the directory from one server to another but dont know how to achieve this task.

Thank You
Reply With Quote
Forum Sponsor
  #2  
Old 12-18-2007
Registered User
 

Join Date: Apr 2006
Posts: 74
Ok. I tried one thing and i just got the 1st part solved.

Code:
find /home/web/dummy -type f | grep "testing"
The output is :-
Code:
/home/web/dummy/mike/testing
/home/web/dummy/john/testing
Once it finds the folder with the specified name "Testing" then i would like to copy this :-

/mike/testing
/john/testing

to my XYZ unix server. How"?
Reply With Quote
  #3  
Old 12-18-2007
blowtorch's Avatar
Supporter
 
Join Date: Dec 2004
Location: Singapore
Posts: 2,328
Are you looking to copy over the entire directory (including content)?

Something like this:
Code:
cd /home/web/dummy
for dir in *; do
   if [ -d ${dir}/testing ]; then
      ssh -l user otherhost "mkdir /home/manage/$dir
      scp -r ${dir}/testing user@otherhost:/home/manage/$dir
   fi
done
This is assuming that you have key-based authentication setup between the hosts. You can also use rsh/rcp, the commands won't really change.
Reply With Quote
  #4  
Old 12-18-2007
Registered User
 

Join Date: Apr 2006
Posts: 74
Mr Torch,

Can i guve you some dukes Dollars ? ;--) Thank you so much. It works perfectly. Just 2 more things to ask may be you can tell me and i can do it. if not then i will post back.

Yes i need to copy the contents under testing folder also. The script is doing that. Say for instance i have :-

/home/web/dummy/mike/testing/check.txt
/home/web/dummy/john/testing/test.txt

when i run the script the first time it copies

/mike/check.txt
/john/test.txt

The second time i run the script and then it does like this:

/mike/testing/check.txt
/john/testing/test.txt

As you can see i would like to have the testing folder also in there. But for some reason it creates the folder the second time i run. Not a biggie i wil try to figure it out.

Thanks anyways
Reply With Quote
  #5  
Old 12-18-2007
Registered User
 

Join Date: Apr 2006
Posts: 74
Ok this is the code i am using:
[code]
cd /home/web/dummy
for dir in *; do
if [ -d ${dir}/testing ]; then
#ssh -l user otherhost "mkdir /home/manage/$dir
scp -r ${dir}/testing user@otherhost:/home/manage/$dir
fi
done
[code]

I tried to change everything i can to make it work but unfortunately i have not succeeded yet. When i run the script the first time it just copies whatever is in testing folder but when i run the code second time everything works fine. My Question is why this is not working the first time when i run my script?

it just copies the contents of testing folder rather than creating a testing folder in XYZ server.

Any help will be really appreciated.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 07:32 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0