Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts

    bulk-copy via putty...?

    Err... I know this isn't Apache config, but this is the closest forum I could find. I figured someone in here would know.

    I've got an updated file sitting in:

    /home/default/mysite.com/user/htdocs/admin_template/myfile.php

    I need to copy that file over the existing versions of it in about a hundred other directories, all having the format:

    /home/default/mysite.com/user/htdocs/user_name/admin/myfile.php

    (where user_name changes each time)

    Is there a simple command-line way of doing this on linux, to save me FTP'ing the same file up into all those dirs manually?

    Fanks

  • #2
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    How about a shell script? Here's a sample:
    Code:
    #!/bin/sh
    #
    
    # Path to the source file
    BASEFILE="/root/myfile.txt"
    # Path to users' home (parent)
    HOMEPATH="/home/"
    # Path to from user dir to destination dir
    TARGETPATH="/testdir123/"
    # Destination filename
    TARGETNAME="target_name.txt"
    
    for userdir in `ls $HOMEPATH`;
    do
        if [ -d $userdir ];
        then
            #echo $userdir;
            if [ -d $HOMEPATH$userdir$TARGETPATH ];
            then
                #echo "cp $BASEFILE $HOMEPATH$userdir$TARGETPATH$TARGETNAME";
                `cp $BASEFILE $HOMEPATH$userdir$TARGETPATH$TARGETNAME`;
            else
                #echo "mkdir $HOMEPATH$userdir$TARGETPATH";
                `mkdir $HOMEPATH$userdir$TARGETPATH`;
                #echo "cp -p $BASEFILE $HOMEPATH$userdir$TARGETPATH$TARGETNAME";
                `cp -p $BASEFILE $HOMEPATH$userdir$TARGETPATH$TARGETNAME`;
            fi;
        fi;
    done;
    I don't make those enough to be good at them, but there are a lot of good Google sources for basic shell scripting.

    EDIT: By the way, it ought to go without saying that you should test before doing this live so you don't clobber something.
    Are you a Help Vampire?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •