...

View Full Version : bulk-copy via putty...?



Spudhead
07-19-2010, 06:55 PM
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 :)

tomws
07-19-2010, 08:50 PM
How about a shell script? Here's a sample:

#!/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. :o



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum