Copy single file to multiple locations - What am I doing wrong
Linux - NewbieThis 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.
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.
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.
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
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
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
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
iirc, you need to change the Internal Field Separator (IFS) shell var. By default it's space or tab or newline, and you want to reduce it to just a newline inside the shell script.
At the top put
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.