Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
Thread: bulk-copy via putty...?
07-19-2010, 06:55 PM #1
- Join Date
- Jun 2002
- London, UK
- 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:
I need to copy that file over the existing versions of it in about a hundred other directories, all having the format:
(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?
07-19-2010, 08:50 PM #2
- Join Date
- Nov 2007
- Thanked 330 Times in 326 Posts
How about a shell script? Here's a sample:
I don't make those enough to be good at them, but there are a lot of good Google sources for basic shell scripting.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;
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?