LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Copy one file to multiple vhost directories (https://www.linuxquestions.org/questions/linux-newbie-8/copy-one-file-to-multiple-vhost-directories-427911/)

thetawaverider 03-24-2006 01:42 AM

Copy one file to multiple vhost directories
 
I'm administering a server that uses Plesk, and I need to copy the vhost.conf file to the conf folder for every vhost that begins with a certain word - we'll call it "unique".

To accomplish this, I tried running the following:
# cp vhost.conf /var/www/vhosts/unique*/conf/

It does copy to one folder, but kicks out the following error for the rest:
cp: omitting directory `/var/www/vhosts/unique1.com/conf/'
cp: omitting directory `/var/www/vhosts/unique2.com/conf/'
.
.
.

I saw someone mention in another thread that it is not possible in Linux to copy one file to multiple directories without a shell script. If this is the case, could someone steer me to a script that would be helpful here? I'd be most grateful.

Thanks,
TWR

Tinkster 03-24-2006 01:51 AM

Something like (untested!) may do it
Code:

for i in `ls /var/www/vhosts/unique*'; do
  cp vhost.conf $i/conf/.
done


Cheers,
Tink

thetawaverider 03-24-2006 02:09 AM

Nice, Tink. Thanks for the quick reply. I'll give it a whirl.

Tinkster 03-24-2006 02:19 AM

Quote:

Originally Posted by thetawaverider
Nice, Tink. Thanks for the quick reply. I'll give it a whirl.

Hope it works ;} ... shouldn't be too hard.


Cheers,
Tink

thetawaverider 03-24-2006 11:31 AM

I ran the script (after changing the ' to a `) and it loops though all the folders inside each of unique0, unique1, etc instead of through the folder names themselves. To remedy this, I changed the command to:

for i in `ls /var/www/vhosts/`;
do
echo $i/conf/
# cp vhost.conf $i/conf/
done

which echos out every folder in the /vhosts folder. Now all I need to do is all a conditional to only echo when the folder name contains the word "unique". Does it require a regular expression? Or are there simpler functions available like strpos in php? Any help would be appreciated.

Thanks,
TWR

Tinkster 03-24-2006 04:57 PM

The "looping through" is easily remedied ...

Code:

for i in `ls -d /var/www/vhosts/unique*`; do
  cp vhost.conf $i/conf/.
done

Sorry about that - must have been a tad tired :}


Cheers,
Tink


All times are GMT -5. The time now is 03:09 PM.