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 and shell scripting languages 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-08-2008 02:53 AM
Copying multiple folders to local machine (don't know folder names) leenyburger UNIX for Dummies Questions & Answers 5 06-12-2008 08:38 AM
decompressed files to specific folders c00kie88 Shell Programming and Scripting 3 04-06-2008 06:41 PM
Copying specific files faaron3 UNIX for Dummies Questions & Answers 3 03-24-2008 01:59 PM
Copying Folders without some folders... ;-) chimpu UNIX for Dummies Questions & Answers 5 04-26-2004 01:25 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-18-2007
chris1234 chris1234 is offline
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
  #2 (permalink)  
Old 12-18-2007
chris1234 chris1234 is offline
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"?
  #3 (permalink)  
Old 12-18-2007
blowtorch's Avatar
blowtorch blowtorch is offline Forum Advisor  
Supporter
  
 

Join Date: Dec 2004
Location: Singapore
Posts: 2,350
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.
  #4 (permalink)  
Old 12-18-2007
chris1234 chris1234 is offline
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
  #5 (permalink)  
Old 12-18-2007
chris1234 chris1234 is offline
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.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:41 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0