Unix Problem (copying specific folders)

Discussion in 'Mac Programming' started by mikemike1234, Dec 19, 2007.

  1. mikemike1234 macrumors newbie

    Joined:
    Dec 19, 2007
    #1
    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 hello@XYZ:/home/manage/$dir
       fi
    done
    
    What i am trying to do is copy specific folder by the name of testing to my other unix server. This is what my directory structure is in server ABC

    /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 , images and source folder. I would like to copy the parent directory which is john or mike and testing folder only to my XYZ server.

    When i run my code the first time, it just copies the contents of testing folder without creating a testing folder. But when i ran the script second time everything works fine. Parent directory which is john or mike is copied to my XYZ server and testing folder is also copied under john and mike.

    Can someone tell me what is going on? why my script is not creating the testing folder the first time ?
     
  2. wrldwzrd89 macrumors G5

    wrldwzrd89

    Joined:
    Jun 6, 2003
    Location:
    Solon, OH
    #2
    For stuff like this I always explicitly create the directory first, after testing to see if it exists.
    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 hello@XYZ:/home/manage/$dir
       fi
    done
    
    I don't know if a missing quote was causing problems at the end of the line that starts with ssh, but I added it.
     
  3. lexfuzo macrumors 6502

    Joined:
    Mar 15, 2005
    Location:
    The heart of Europe
    #3
    why not rsync?

    like
    rsync -e ssh -avz --include=*testing this/host other/host
    or so
     
  4. mikemike1234 thread starter macrumors newbie

    Joined:
    Dec 19, 2007
    #4
    Thanks dude. But that was a typo from my side that missing quote. Still same thing.
     
  5. mikemike1234 thread starter macrumors newbie

    Joined:
    Dec 19, 2007
    #5
    rsync not possible

    I am not the administrator of the machine. So i doubt if i can install rsync in there. Any other clues?
     

Share This Page