LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-24-2006, 02:42 AM   #1
thetawaverider
Member
 
Registered: Feb 2006
Distribution: CentOS
Posts: 47

Rep: Reputation: 15
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

Last edited by thetawaverider; 07-26-2007 at 04:19 PM.
 
Old 03-24-2006, 02:51 AM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Something like (untested!) may do it
Code:
for i in `ls /var/www/vhosts/unique*'; do
  cp vhost.conf $i/conf/.
done

Cheers,
Tink
 
Old 03-24-2006, 03:09 AM   #3
thetawaverider
Member
 
Registered: Feb 2006
Distribution: CentOS
Posts: 47

Original Poster
Rep: Reputation: 15
Nice, Tink. Thanks for the quick reply. I'll give it a whirl.
 
Old 03-24-2006, 03:19 AM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
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
 
Old 03-24-2006, 12:31 PM   #5
thetawaverider
Member
 
Registered: Feb 2006
Distribution: CentOS
Posts: 47

Original Poster
Rep: Reputation: 15
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

Last edited by thetawaverider; 07-26-2007 at 04:19 PM.
 
Old 03-24-2006, 05:57 PM   #6
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy files from multiple directories into one directory MadRabbit Linux - Newbie 8 02-07-2014 08:56 PM
Searching multiple directories and sub directories for a file jeep99899 Linux - Newbie 2 10-13-2005 01:23 PM
Copy one file to multiple directories cmfarley19 Linux - General 9 11-10-2004 01:57 PM
find and copy files into multiple directories avargas22 Linux - Newbie 2 04-01-2004 12:11 PM
How to copy one file in all users directories aizkorri Programming 1 09-02-2002 08:32 AM


All times are GMT -5. The time now is 02:56 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration