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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
04-03-2008, 06:05 AM
|
#1
|
LQ Newbie
Registered: Jul 2007
Posts: 9
Rep:
|
Copy single file to multiple locations - What am I doing wrong
Hi
I have a little server running qmail/plesk . The problem is my ISP wont support Spamassassin due to load issues on the host server and I cannot afford to migrate to a root server (using VMWARE at the mo).
I have spamassassin installed manually but also need to use plesk for adding domains and I got it working. Problem is it is set up by default to rewrite_headers and accept the message. I need to reject it via the .qmail files.
I have one .qmail file and I need to copy it over every users .qmail file. Here is what I am trying.
Code:
cp ./.qmail /var/qmail/mailnames/*/.qmail
Where * can be any domain.
However the cp command complains that /var/qmail/mailnames/*/.qmail is not a directory. I already know that and want to overwrite the file. if I omit the .qmail file and do cp ./.qmail /var/qmail/mailnames/*/ it returns a message like 'Omitting directory example.com/ ....'
What am I doing wrong. All I want to do is copy one file to multiple folders which are all level one sub-folders of a parent folder we know the path to.
By the way ln -s gives exactly the same error
Thanks in advance
|
|
|
04-03-2008, 07:14 AM
|
#2
|
LQ Guru
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509
|
The problem is that when the wildcard is expanded the command line looks like
Code:
cp ./.qmail /var/qmail/mailnames/user1/.qmail /var/qmail/mailnames/user2/.qmail /var/qmail/mailnames/user2/.qmail
and the error message tells you that when you have multiple sources the last entry in the command line should be a destination directory. You cannot copy a single source file to multiple destination, whereas you can copy multiple sources to one destination. You can solve this by a simple for loop:
Code:
# for dest in /var/qmail/mailnames/*
> do
> cp ./.qmail $dest
> done
but first check that /var/qmail/mailnames/* expands to the directories you want to copy the file into. If it happens that you have a file in /var/qmail/mailnames, it will overwritten by .qmail. In this case you can refine the criteria as in
Code:
# for dest in $(find /var/qmail/mailnames -mindepth 1 -type d)
> do
> cp ./.qmail $dest
> done
|
|
|
04-03-2008, 07:30 AM
|
#3
|
LQ Newbie
Registered: Jul 2007
Posts: 9
Original Poster
Rep:
|
Excellent, thanks for the quick response. Works a treat. See what you mean about refining. Nearly orverwrote my quota files.
Thanks again, this is the best tip I've had for ages. I badly need to develop my bash scripting skills, do you know of any resources?
Quote:
Originally Posted by colucix
The problem is that when the wildcard is expanded the command line looks like
Code:
cp ./.qmail /var/qmail/mailnames/user1/.qmail /var/qmail/mailnames/user2/.qmail /var/qmail/mailnames/user2/.qmail
and the error message tells you that when you have multiple sources the last entry in the command line should be a destination directory. You cannot copy a single source file to multiple destination, whereas you can copy multiple sources to one destination. You can solve this by a simple for loop:
Code:
# for dest in /var/qmail/mailnames/*
> do
> cp ./.qmail $dest
> done
but first check that /var/qmail/mailnames/* expands to the directories you want to copy the file into. If it happens that you have a file in /var/qmail/mailnames, it will overwritten by .qmail. In this case you can refine the criteria as in
Code:
# for dest in $(find /var/qmail/mailnames -mindepth 1 -type d)
> do
> cp ./.qmail $dest
> done
|
|
|
|
04-22-2008, 06:17 PM
|
#4
|
Member
Registered: Jun 2007
Location: Troy, Michigan, USA
Distribution: Gentoo
Posts: 30
Rep:
|
Is there a way to get this to work with directories that have spaces in their names? This is a great solution otherwise. Whenever I try this, it copies my file into directories with no spaces just fine, but if the directory has a space in the name, i end up with a file named the first part of the directory name in the directory above it.
Quote:
Originally Posted by colucix
The problem is that when the wildcard is expanded the command line looks like
Code:
cp ./.qmail /var/qmail/mailnames/user1/.qmail /var/qmail/mailnames/user2/.qmail /var/qmail/mailnames/user2/.qmail
and the error message tells you that when you have multiple sources the last entry in the command line should be a destination directory. You cannot copy a single source file to multiple destination, whereas you can copy multiple sources to one destination. You can solve this by a simple for loop:
Code:
# for dest in /var/qmail/mailnames/*
> do
> cp ./.qmail $dest
> done
but first check that /var/qmail/mailnames/* expands to the directories you want to copy the file into. If it happens that you have a file in /var/qmail/mailnames, it will overwritten by .qmail. In this case you can refine the criteria as in
Code:
# for dest in $(find /var/qmail/mailnames -mindepth 1 -type d)
> do
> cp ./.qmail $dest
> done
|
|
|
|
04-22-2008, 06:41 PM
|
#6
|
Member
Registered: Aug 2003
Location: Oregon
Distribution: Ubuntu
Posts: 51
Rep:
|
does this help?
1) link to Advanced Bash Scripting Guide:
http://tldp.org/LDP/abs/html/
2)
[lcole@harley ~]$ find ~/"space in name" -mindepth 1 -type d
/home/lcole/space in name/a
/home/lcole/space in name/b
/home/lcole/space in name/a b
|
|
|
04-22-2008, 08:15 PM
|
#7
|
Member
Registered: Jun 2007
Location: Troy, Michigan, USA
Distribution: Gentoo
Posts: 30
Rep:
|
thank you for the fast responses  some new things to try, i'll keep you posted.
|
|
|
04-26-2008, 04:09 PM
|
#8
|
Member
Registered: Jun 2007
Location: Troy, Michigan, USA
Distribution: Gentoo
Posts: 30
Rep:
|
just to update, setting IFS worked great, thanks
Quote:
Originally Posted by kaelthas
thank you for the fast responses  some new things to try, i'll keep you posted.
|
|
|
|
All times are GMT -5. The time now is 07:19 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|